Skip to content

Instantly share code, notes, and snippets.

@kitze
Created February 25, 2018 13:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitze/8b438f50943a80e2646b6a4b8d14a8f2 to your computer and use it in GitHub Desktop.
Save kitze/8b438f50943a80e2646b6a4b8d14a8f2 to your computer and use it in GitHub Desktop.
MST & TS
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