Created
January 27, 2018 09:47
-
-
Save jjrv/3083569f7f57004527096621f42e4571 to your computer and use it in GitHub Desktop.
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
{ | |
"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" | |
} | |
} |
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
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) | |
} | |
}) | |
}) |
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
Show hidden characters
{ | |
"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