Created
December 22, 2015 19:48
-
-
Save arackaf/a896bd234336ec68a63a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 bookListSelector = state => ({ | |
subjects: Object.assign({}, state.bookList.subjects, {list: stackAndGetTopLevelSubjects(state.bookList.subjects.list)}), | |
books: Object.assign({}, state.bookList.books, {list: booksWithSubjectsSelector(state.bookList)}) | |
}); | |
function stackAndGetTopLevelSubjects(subjectsHash){ | |
let subjects = Object.keys(subjectsHash).map(_id => subjectsHash[_id]); | |
subjects.forEach(s => { | |
s.children = []; | |
s.children.push(...subjects.filter(sc => new RegExp(`,${s._id},$`).test(sc.path))); | |
}); | |
return subjects.filter(s => s.path == null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment