Skip to content

Instantly share code, notes, and snippets.

@ArthurClemens
Created September 23, 2015 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArthurClemens/af349a86b6ec72a164e4 to your computer and use it in GitHub Desktop.
Save ArthurClemens/af349a86b6ec72a164e4 to your computer and use it in GitHub Desktop.
Example of mithril-infinite and retrieving json data from a server
'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