Created
February 25, 2018 13:45
-
-
Save kitze/8b438f50943a80e2646b6a4b8d14a8f2 to your computer and use it in GitHub Desktop.
MST & TS
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} from 'mobx-state-tree'; | |
export const TodoModel = types.model({ | |
title: types.string, | |
age: types.number | |
}); | |
export const Todo = TodoModel.actions((self: ITodo) => ({ | |
setTitle: (title: string) => { | |
self.title = title; | |
} | |
})); | |
type TodoModelType = typeof TodoModel.Type; | |
interface ITodo extends TodoModelType {} | |
const StoreModel = types.model('Store', { | |
todos: types.optional(types.array(Todo), []) | |
}); | |
export const Store = StoreModel.actions((self: StoreModelType) => ({ | |
addTodo: name => { | |
self.todos.push; | |
}, | |
removeTodo: id => { | |
self.todos.filter(todo => todo.age !== id); | |
} | |
})); | |
export type StoreModelType = typeof StoreModel.Type; | |
export type IStoreType = typeof Store.Type; | |
export interface IStore extends IStoreType {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment