react-code-dataset / wp-calypso /apps /notifications /src /panel /state /selectors /get-all-notes.js
react-code-dataset / wp-calypso /apps /notifications /src /panel /state /selectors /get-all-notes.js
Download wp-calypso/apps/notifications/src/panel/state/selectors/get-all-notes.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/apps/notifications/src/panel/state/selectors/get-all-notes.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/apps/notifications/src/panel/state/selectors/get-all-notes.js
-
curl -L -o get-all-notes.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/apps/notifications/src/panel/state/selectors/get-all-notes.js
1.11 kB
| import getNotes from './get-notes'; | |
| let prevAllNotes; | |
| let sortedNotes = []; | |
| const byTimestamp = ( a, b ) => Date.parse( a.timestamp ) - Date.parse( b.timestamp ); | |
| const byId = ( a, b ) => a.id - b.id; | |
| /** | |
| * Returns all available notification data | |
| * | |
| * The caching in this function should be | |
| * replaced with a proper memoizer instead | |
| * of relying on this intermingled system. | |
| * However, in order to keep the changeset | |
| * small we are copying over this non-ideal | |
| * code until more formal refactorings. | |
| * @param {Object} notesState | |
| * @returns {Object[]} list of notification objects | |
| */ | |
| export const getAllNotes = ( notesState ) => { | |
| const nextAllNotes = notesState.allNotes; | |
| if ( prevAllNotes === nextAllNotes ) { | |
| return sortedNotes; | |
| } | |
| prevAllNotes = nextAllNotes; | |
| sortedNotes = Object.values( nextAllNotes ) | |
| .sort( ( a, b ) => { | |
| const chronologicalOrder = byTimestamp( a, b ); | |
| if ( chronologicalOrder === 0 ) { | |
| return byId( a, b ); | |
| } | |
| return chronologicalOrder; | |
| } ) | |
| .reverse(); | |
| return sortedNotes; | |
| }; | |
| export default ( state ) => getAllNotes( getNotes( state ) ); | |