Skip to content

Instantly share code, notes, and snippets.

@alexvcasillas
Last active June 23, 2017 06:35
Show Gist options
  • Save alexvcasillas/0d72f0b371155cef64d8cc4d8ab509b2 to your computer and use it in GitHub Desktop.
Save alexvcasillas/0d72f0b371155cef64d8cc4d8ab509b2 to your computer and use it in GitHub Desktop.
mst-store-element
import { types } from 'mobx-state-tree';
// USER MODEL THAT COULD BE USED/IMPORTED ANYWHERE IN THE APP
const User = types.model(
{
name: types.string,
lastName: types.string,
get fullName(){
return `${this.name} ${this.lastName}`;
},
{
setName(name){
this.name = name
},
setLastName(lastName){
this.lastName = lastName
}
}
);
// USER STORE THAT WILL BE INJECTED TO COMPONENTS
const UserStore = types.store(
{
users: types.optional(types.array(User), [])
},
{
addUser(user){
this.users.push(user);
},
clearUsers(){
this.users.clear();
}
}
);
export default UserStore;
export { User };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment