Last active
February 26, 2020 01:40
-
-
Save jwulf/1a38076de9ce19bd5e72f0b809e7c66d to your computer and use it in GitHub Desktop.
A code sample from the article https://www.joshwulf.com/blog/2020/02/avoid-global-state/
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 GlobalMemberStore = (() => { | |
let _members = [] | |
const Store = { | |
updateMember: update => { | |
const member = Store.getMember(update.id) | |
if (!member.found) { | |
throw new Error(`No member with id ${update.id} in the store!`) | |
} | |
_members = _members.map(m => m.id === update.id ? | |
{...update} : m) | |
} | |
} | |
return Store | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment