Skip to content

Instantly share code, notes, and snippets.

@arackaf
Last active November 23, 2016 02:57
Show Gist options
  • Save arackaf/f10cb1e850c241d93428f84d660d4813 to your computer and use it in GitHub Desktop.
Save arackaf/f10cb1e850c241d93428f84d660d4813 to your computer and use it in GitHub Desktop.
11-22-16-SearchSubjectsForBooks
const unwindSubjects = subjects => {
let result = [];
subjects.concat().sort(subjectSortCompare).forEach(s => {
result.push(s);
result.push(...unwindSubjects(s.children));
});
return result;
};
const stackedSubjectsSelector = createSelector([state => state.app.subjectHash],
subjectHash => {
let mainSubjectsCollection = stackAndGetTopLevelSubjects(subjectHash),
subjectsUnwound = unwindSubjects(mainSubjectsCollection);
return {
subjects: mainSubjectsCollection,
allSubjectsSorted: allSubjectsSorted(subjectHash),
subjectsUnwound: subjectsUnwound
};
}
);
const searchSubjectsSelector = createSelector([
stackedSubjectsSelector,
state => state.booksModule.subjects.subjectSearch
], (stackedSubjects, subjectSearch) => ({ ...stackedSubjects, subjectsSearched: filterSubjects(stackedSubjects.subjectsUnwound, subjectSearch) }));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment