使用代理的轻量级、快速状态管理工具。
Dob Dob 是一个用于监控对象变化的工具。使用 Proxy. 在线文档。
在 fiddle 上有几个 示例。这里是最简单的一个:
import { observable, observe } from "dob";
const obj = observable({ a: 1 });
observe(() => {
console.log("obj.a has changed to", obj.a);
}); // Use `inject` to pick stores in action, do not `new UserStore()`, it's terrible for later maintenance.
## Use in react project
TypeScript import { Action, observable, combineStores, inject } from "dob"; import { Provider, Connect } from "dob-React"; @observable export class UserStore { name = "bob"; } export class UserAction { @Inject(UserStore) userStore: UserStore; @Action setName() { this.userStore.name = "lucy"; } }
@连接 class App extends React.Component { render() { return ( {this.props.UserStore.name} ); } } ReactDOM.render() , document.getElementById("React-dom") );
…TypeScript class A { @inject(B) b; } class B { @inject(A) a; }
### Do not deconstruct to the last level on dynamic object
TypeScript const obj = observable({ a: 1 }); // 很好 obj.a = 5; // 错误 let { a } = obj; a = 5;
## 受到启发
* [mobx](https://github.com/mobxjs/mobx)
* [nx-js](https://github.com/nx-js/observer-util)暂无开放 Issues,或尚未同步最近议题。