Last active
April 23, 2021 19:11
-
-
Save wazazaby/69e600a11f240ed653416c5c5f7ff6be 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
// From snapshot to a simple JS object | |
const getObjFromDocumentSnapshot = snapshot => snapshot.data(); | |
// From an object like this -> { 'RIP Code': { en: { '8274': 'My english value' } } } | |
// To this -> 'My english value' | |
const getter = propName => either(pipe(path([propName, 'en']), values, head), always('')); | |
const ripCodeGetter = getter('RIP Code'); | |
// Check if the RIP Code property of the given object matchs ripCode | |
const ripCodeExistsInObj = ripCode => pipe(ripCodeGetter, equals(ripCode)); | |
// Same, but on a snapshot instead of an object | |
const ripCodeExistsInSnapshot = ripCode => pipe(getObjFromDocumentSnapshot, ripCodeExistsInObj(ripCode)); | |
// Same, but on a list of snapshots instead of a single one | |
const ripCodeExistsInSnapshots = curry((ripCode, querySnapshots) => any(ripCodeExistsInSnapshot(ripCode))(querySnapshots)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment