npm: possibly marvellous

    rocket-science-model

    0.0.0 • Public • Published

    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
        }
      }
    })

    Keywords

    none

    Install

    npm i rocket-science-model

    DownloadsWeekly Downloads

    1

    Version

    0.0.0

    License

    MIT

    Last publish

    Collaborators

    • nhunzaker