Skip to content

Instantly share code, notes, and snippets.

@chenyong
Created December 7, 2017 03:32
Show Gist options
  • Save chenyong/baabc068b70dca17982d9d65f1281bc0 to your computer and use it in GitHub Desktop.
Save chenyong/baabc068b70dca17982d9d65f1281bc0 to your computer and use it in GitHub Desktop.
some code to try mobx-state-tree
types = require('mobx-state-tree').types
M1 = types
.model
a: types.string
b: types.frozen
c: types.map(types.number)
.actions (self) ->
changeA: (x) -> self.a = x
changeB: (y) -> self.b = y
changeC: (x) -> self.c.set 'a2', x
m1 = M1.create a: "demo", b: ['a','b', ['c', 'd']], c: {a: 1}
console.log m1.c.get('a')
m1.changeC(33)
console.log m1.c.toJSON()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment