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 needsArg = arg => { | |
if (!member) { | |
throw new Error (`Undefined passed as argument to Store!`) | |
} | |
return arg | |
} | |
const needsId = member => { | |
if (!member.id) { |
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 = { | |
putMember: member => { | |
if (Store.getMember(member.id).found) { | |
throw new Error(`${member.id} already exists!`) | |
} | |
_members = [..._members, {...member}] | |
} | |
} |
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) |
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 = { | |
} | |
return Store | |
})() |
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 = [] | |
return { | |
getMember: id => { | |
const member = _members.filter(m => m.id === id) | |
return member.length === 1 ? | |
{ found: true, member: {...member[0]}} : | |
{ found: false, member: undefined } | |
} | |
} |
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 = [] | |
return { | |
getMember: id => _members.filter(m => m.id === id) | |
} | |
})() |
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 = [] | |
return { | |
updateMember: update => (_members = _members.map(m => m.id === update.id ? | |
{...update} : m)) | |
} | |
})() |
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 = [] | |
return { | |
setMembers: members => _members = members.map(m => ({...m})) | |
} | |
})() |
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 = [] | |
return { | |
getMembers: () => _members.map(m => ({...m})) | |
} | |
})() |
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 = [] | |
return { | |
getMembers: () => [..._members] | |
} | |
})() |