Created
October 31, 2017 13:18
-
-
Save Chalarangelo/04c8ed7c29eb75a812e620dd10017fa1 to your computer and use it in GitHub Desktop.
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 characters
const posts = (state = {data: [], selected: []}, action) => { | |
let posts = {data: [], selected: []}; | |
switch(action.type){ | |
case VIEW_ALL: | |
Object.assign(posts.data, state.data); | |
posts.selected = []; | |
return posts; | |
case SEARCH_POST: | |
Object.assign(posts.data, state.data); | |
let search = new JsSearch.Search('date-added'); | |
search.addIndex('title'); | |
search.addIndex('tags'); | |
search.addIndex('author'); | |
search.addDocuments(posts.data); | |
posts.selected = search.search(action.query).map(searchResult => searchResult.id); | |
return posts; | |
case UPDATE_POSTS: | |
Object.assign(posts.data, action.posts.data); | |
return posts; | |
default: | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment