Created
September 23, 2015 21:08
-
-
Save ArthurClemens/af349a86b6ec72a164e4 to your computer and use it in GitHub Desktop.
Example of mithril-infinite and retrieving json data from a server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import m from 'mithril'; | |
import infinite from 'mithril-infinite'; | |
const item = (data) => { | |
return m('.item', | |
{ | |
style: { | |
background: '#eee', | |
padding: '20px', | |
height: '200px', | |
'margin-bottom': '2px' | |
} | |
}, | |
m('h2', data.name), | |
m('p', data.repository.name), | |
m('a', {href: data.html_url, config: null}, 'Link to code') | |
); | |
}; | |
const getPageData = (pageNum) => { | |
//console.log(pageNum); | |
return m.request({ | |
method: 'GET', | |
url: 'https://api.github.com/search/code?q=javascript+user%3Amozilla&per_page=10&page=' + pageNum, | |
unwrapSuccess: function(response) { | |
return response.items; | |
}, | |
unwrapError: function(response) { | |
return response.error; | |
} | |
}); | |
}; | |
const component = {}; | |
component.controller = () => { | |
return { | |
pageData: getPageData | |
} | |
}; | |
component.view = (ctrl) => { | |
return m.component(infinite, { | |
item: item, | |
pageData: ctrl.pageData | |
}); | |
}; | |
export default component; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment