sdio
v0.0.3
Published
a react state management library supports local and global state
Downloads
1
Readme
sdio
sdio是一个react的状态管理库, 支持局部状态和全局状态
Examples
import { Store, state, effect, action, selector, StoreComponent } from 'sdio';
class TodoStore extends Store {
@state todos = [];
@state filter = 'SHOW_ALL';
@selector(state => state.todos, state => filter)
filterTodos (todos, filter){
switch (filter) {
case 'SHOW_ALL':
return todos
case 'SHOW_COMPLETED':
return todos.filter(todo => todo.completed)
case 'SHOW_ACTIVE':
return todos.filter(todo => !todo.completed)
}
}
@action addTodo(todo) {
this.todos = [...this.todos, todo];
}
@action setTodos(todos) {
this.todos = todos;
}
@effect async getTodos() {
const todos = api.get();
this.setTodos(todos);
}
}
class Todo extends StoreComponent {
}