From 9ab5f7cae5101d06ebd152301141d3641a156c61 Mon Sep 17 00:00:00 2001 From: Rastislav Lamos Date: Tue, 23 May 2017 10:30:30 +0200 Subject: [PATCH] Move data fetchers to data.js file Props @mtias for the suggestion --- blocks/library/latest-posts/data.js | 18 ++++++++++++++++++ blocks/library/latest-posts/index.js | 13 +------------ 2 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 blocks/library/latest-posts/data.js diff --git a/blocks/library/latest-posts/data.js b/blocks/library/latest-posts/data.js new file mode 100644 index 00000000000000..c25ed3da4b3a6c --- /dev/null +++ b/blocks/library/latest-posts/data.js @@ -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; +} + diff --git a/blocks/library/latest-posts/index.js b/blocks/library/latest-posts/index.js index c060cc15c6040e..2d96d03f531ded 100644 --- a/blocks/library/latest-posts/index.js +++ b/blocks/library/latest-posts/index.js @@ -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 (