Skip to content

Commit 9ab5f7c

Browse files
committed
Move data fetchers to data.js file
Props @mtias for the suggestion
1 parent 6816ef4 commit 9ab5f7c

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Returns a Promise with the latest posts or an error on failure.
3+
*
4+
* @param {Number} postsToShow
5+
* @returns {Object}
6+
*/
7+
export function getLatestPosts( postsToShow = 5 ) {
8+
const postsCollection = new wp.api.collections.Posts();
9+
10+
const posts = postsCollection.fetch( {
11+
data: {
12+
per_page: postsToShow
13+
}
14+
} );
15+
16+
return posts;
17+
}
18+

blocks/library/latest-posts/index.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,7 @@ import Placeholder from 'components/placeholder';
77
* Internal dependencies
88
*/
99
import { registerBlock } from '../../api';
10-
11-
function getLatestPosts( postsToShow = 5 ) {
12-
const postsCollection = new wp.api.collections.Posts();
13-
14-
const posts = postsCollection.fetch( {
15-
data: {
16-
per_page: postsToShow
17-
}
18-
} );
19-
20-
return posts;
21-
}
10+
import { getLatestPosts } from './data.js';
2211

2312
function renderList( latestPosts ) {
2413
return (

0 commit comments

Comments
 (0)