特点
轻量级的对象状态
管理开源项目
小的应用程序大小(~2Kb)
易于使用任何框架,只需在变化时回调
关于AnyState
AnyState是一个使用Typescript构建的开源程序(为了更安全的环境)
使用方法
用createStore()初始化anyState对象 :
const anyState = createStore({
name: 'John',
age: 30,
children: [{
name: 'Bob',
age: 5,
}]
});
设置状态
anyState.setState({
name: 'John',
age: 30,
children: [{
name: 'Bob',
age: 5,
}]
});
获取状态
const state = anyState.getState();
设置项目
// const path = 'name';
const path = 'children[0].name'; // the path to the item
anyState.setItem(path, 'Jane');
获取项目
const path = 'children[0]';
const child = anyState.getItem(path);
观察onChange
const path = 'name'; // path to item
anyState.watch(path, (nextState, prevState) => {
// do anything
});
编码愉快!
接受任何建议。