将代理与 mobx 商店一起使用
Using Proxy with mobx Store
我有一个带有 React 和 Mobx 的应用程序,我想将所有记录用户交互(操作调用)与 Mobx 存储分开,所以我做了一些搜索,我发现代理模式是这个员工和我的最佳方式问题是在我的案例中如何使用 Mobx 和代理。
谢谢
您可以使用 spy 来达到这个目的。
示例 (JS Bin)
class Store {
@observable count = 1;
@action
increment(step) {
this.count = this.count + step;
}
}
const store = new Store();
setInterval(() => store.increment(store.count), 1000);
spy((event) => {
if (event.type === 'action') {
console.log(`${event.name} with args: ${event.arguments}`);
}
});
我有一个带有 React 和 Mobx 的应用程序,我想将所有记录用户交互(操作调用)与 Mobx 存储分开,所以我做了一些搜索,我发现代理模式是这个员工和我的最佳方式问题是在我的案例中如何使用 Mobx 和代理。 谢谢
您可以使用 spy 来达到这个目的。
示例 (JS Bin)
class Store {
@observable count = 1;
@action
increment(step) {
this.count = this.count + step;
}
}
const store = new Store();
setInterval(() => store.increment(store.count), 1000);
spy((event) => {
if (event.type === 'action') {
console.log(`${event.name} with args: ${event.arguments}`);
}
});