Last active
September 1, 2017 20:21
Revisions
-
rupeshtiwari renamed this gist
Sep 1, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
rupeshtiwari created this gist
Sep 1, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ // Code goes here const {createSelector} = Reselect ; const state = { posts: [ { title:'testing', id: 1 }, { title:'playing', id: 2 }, { title: 'dancing', id: 3 }, { title: 'singing', id: 4 } ], selectedPostIds : [ 1, 3, 4 ] }; // selector const getPosts = state => state.posts; const getSelectedPostIds = state => state.selectedPostIds; console.log( 'all posts' , getPosts(state) ); console.log( 'selected post ids' , getSelectedPostIds(state) ); // reselect selector const getSelectedPosts = createSelector( getPosts, getSelectedPostIds, (posts, ids) => posts.filter(p=>ids.indexOf(p.id)>-1) ); console.log( 'selected posts' , getSelectedPosts(state));