Skip to content

Commit

Permalink
Move data fetchers to data.js file
Browse files Browse the repository at this point in the history
Props @mtias for the suggestion
  • Loading branch information
lamosty committed May 24, 2017
1 parent 6816ef4 commit 9ab5f7c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
18 changes: 18 additions & 0 deletions blocks/library/latest-posts/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Returns a Promise with the latest posts or an error on failure.
*
* @param {Number} postsToShow
* @returns {Object}
*/
export function getLatestPosts( postsToShow = 5 ) {
const postsCollection = new wp.api.collections.Posts();

const posts = postsCollection.fetch( {
data: {
per_page: postsToShow
}
} );

return posts;
}

13 changes: 1 addition & 12 deletions blocks/library/latest-posts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,7 @@ import Placeholder from 'components/placeholder';
* Internal dependencies
*/
import { registerBlock } from '../../api';

function getLatestPosts( postsToShow = 5 ) {
const postsCollection = new wp.api.collections.Posts();

const posts = postsCollection.fetch( {
data: {
per_page: postsToShow
}
} );

return posts;
}
import { getLatestPosts } from './data.js';

function renderList( latestPosts ) {
return (
Expand Down

0 comments on commit 9ab5f7c

Please sign in to comment.