Last active
June 23, 2017 06:35
-
-
Save alexvcasillas/0d72f0b371155cef64d8cc4d8ab509b2 to your computer and use it in GitHub Desktop.
mst-store-element
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
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