Created
November 23, 2019 19:19
-
-
Save terrysahaidak/cbe57f2028705bba7d69d2cede62d8ff to your computer and use it in GitHub Desktop.
Generic user store
This file contains 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
let UserModel; | |
const ResolveUser = types | |
.model('ResolveUser', { | |
id: types.identifier, | |
}) | |
.views((self) => ({ | |
get user() { | |
return resolveIdentifier(UserModel, self, self.id); | |
}, | |
})); | |
const UserSettingsModel = ResolveUser.named('UserSettings').props({ | |
height: types.number, | |
color: types.string, | |
}); | |
const UserShopModel = ResolveUser.named('UserShop').props({ | |
name: types.string, | |
}); | |
UserModel = types | |
.model('User', { | |
id: types.identifier, | |
firstName: types.string, | |
lastName: types.string, | |
settings: types.reference(UserSettingsModel), | |
shop: types.reference(UserShopModel), | |
}) | |
.preProcessSnapshot((snapshot) => ({ | |
settings: snapshot.id, | |
shop: snapshot.id, | |
})); | |
const UserStore = types.model('UserStore', { | |
users: types.map(UserModel), | |
shopUsers: types.map(UserShopModel), | |
settingUsers: types.map(UserSettingsModel), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment