Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // which is better
- // For each case, read code from bottom to top
- // CASE 1
- // less refactoring, but fn's aren't necessarily following DO ONE THING
- const searchResultsDiffer = (searchResults, kvs) =>
- searchResults.map(
- book =>
- kvs[book.id]
- ? kvs[book.id]
- : book.shelf ? { ...book, shelf: false } : book
- );
- const SearchViewDiffer = (nextProps, prevState) => {
- return {
- query: prevState.query,
- searchResults: searchResultsDiffer(
- prevState.searchResults,
- nextProps.shelfKeyValueStore
- )
- };
- };
- //---------------------------------------------------------------------
- // CASE 2
- // fn's do less, but more code
- const returnFormattedBook = book => ({ ...book, shelf: false });
- const bookShelfChecker = book =>
- book.shelf ? returnFormattedBook(book) : book;
- const bookRecordExists = (kvs, book) => (kvs[book.id] ? true : false);
- const searchResultsDiffer = (searchResults, kvs) =>
- searchResults.map(
- book =>
- bookRecordExists(kvs, book) ? kvs[book.id] : bookShelfChecker(book)
- );
- const SearchViewDiffer = (nextProps, prevState) => ({
- query: prevState.query,
- searchResults: searchResultsDiffer(
- prevState.searchResults,
- nextProps.shelfKeyValueStore
- )
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement