Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pearofducks/7e053fe6ad785c5290ca68ac3e23bcaf to your computer and use it in GitHub Desktop.
Save pearofducks/7e053fe6ad785c5290ca68ac3e23bcaf to your computer and use it in GitHub Desktop.
mobx basic crud
class FooStore {
@observable foos = []
getFoos = () => {
return this.foos
}
getFoo = id => {
return this.foos.find(foo => foo.id === id)
}
addFoo = text => {
this.foos.push({ id: Math.random(), bar })
}
removeFoo = id => {
this.foos = this.foos.filter(foo => foo.id !== id)
}
}
const fooStore = new FooStore()
export default fooStore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment