rocket-science-model
v0.0.0
Published
A draft of Rocket Science collections.
Downloads
3
Readme
Rocket Science Model
A draft for Rocket Science Collections and Models
Usage
var Model = require('rocket-science-model').Model
var Collection = require('rocket-science-model').Collection
var User = Model({
firstName : '',
lastName : '',
fullName : function () {
return this.firstName + ' ' this.lastName
}
})
var Users = Collection({
model: User
})
var users = Users.getInitialState() // Map()
var next = Users.add(users, { id: 1, firstName: 'Billy', lastName: 'Booster' })
console.log(Users.get(next, 1).fullName) // 'Billy Booster'
Usage with Microcosm
Collections are designed according to the same interface as Stores. To hook a collection into Microcosm as a store:
var Actions = require(actions)
var Users = Collection({
model: User,
register() {
return {
[Actions.add] : Users.add,
[Actions.remove] : Users.remove,
[Actions.reset] : Users.reset
}
}
})