1

我有一个带有 react 和 mobx 的应用程序,我想将所有日志记录用户交互(操作调用)与 Mobx 商店分开,所以我做了一些搜索,我发现代理模式是这个员工的最佳方式,我的问题是我怎么能在我的情况下使用 Mobx 和代理。谢谢

4

1 回答 1

0

您可以为此目的使用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}`);
  }
});
于 2017-03-18T13:00:35.627 回答