Skip to content

Instantly share code, notes, and snippets.

@jjrv
Created January 27, 2018 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjrv/3083569f7f57004527096621f42e4571 to your computer and use it in GitHub Desktop.
Save jjrv/3083569f7f57004527096621f42e4571 to your computer and use it in GitHub Desktop.
{
"private": true,
"name": "classy-test",
"scripts": {
"install": "cd node_modules && git clone https://github.com/charto/classy-mst.git && cd classy-mst && git checkout develop && tsc -d --outdir dist src/index.ts src/classy-mst.ts",
"test": "tsc && mocha"
},
"license": "MIT",
"devDependencies": {
"@types/mocha": "^2.2.47",
"mocha": "^2.5.3",
"typescript": "^2.6.2"
},
"dependencies": {
"@types/node": "^9.4.0",
"mobx": "^3.4.1",
"mobx-state-tree": "^1.3.1"
}
}
import {types, flow} from 'mobx-state-tree'
import {mst, shim, action} from 'classy-mst'
const TodoData = types
.model({
title: types.string,
done: false
})
.named('TodoData')
class TodoCode extends shim(TodoData) {
get isDone(): boolean {
return this.done
}
@action
toggle() {
this.done = !this.done
}
@action
run() {
return flow(function*() {
yield Promise.resolve('This gets lost')
return 'Returned value'
})()
}
}
const Todo = mst(TodoCode, TodoData)
const NewTodoData = Todo.props({count: 0})
class NewTodoCode extends shim(NewTodoData, Todo) {
@action
toggle() {
console.log('Toggled ' + ++this.count + ' times!')
super.toggle()
}
}
const NewTodo = mst(NewTodoCode, NewTodoData)
describe('hello', () => {
it('first', async done => {
try {
const t = Todo.create({title: '123'})
t.toggle()
console.log(await t.run())
console.log(t.isDone)
done()
} catch (e) {
done(e)
}
})
})
{
"compileOnSave": true,
"compilerOptions": {
"declaration": true,
"experimentalDecorators": true,
"lib": [ "es5", "es2015.collection", "es2015.promise" ],
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitThis": true,
"removeComments": false,
"strictNullChecks": true,
"target": "es5"
},
"files": [
"test.ts"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment