Created
March 28, 2017 21:34
-
-
Save jimbol/edbf0d4a7be235bf9befb7dc58d9481c to your computer and use it in GitHub Desktop.
Helpers for hash reducers
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 update = (id, hash, changes) => { | |
const newHash = hash; | |
const updateEntity = { ...newHash[id], ...changes }; | |
newHash[id] = updateEntity; | |
return newHash; | |
}; | |
const replace = (id, nextEntity, hash) => { | |
let newHash = hash; | |
newHash = remove(id, newHash); | |
newHash = add(nextEntity, newHash); | |
return newHash; | |
}; | |
const remove = (id, hash) => { | |
const newHash = hash; | |
delete newHash[id]; | |
return newHash; | |
}; | |
const add = (entity, hash) => { | |
const newHash = hash; | |
newHash[entity.id] = entity; | |
return newHash; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment