使用代理与mobx商店

时间:2017-03-18 12:10:19

标签: javascript proxy mobx mobx-react

我有一个带有react和mobx的应用程序,我想从Mobx商店中分离所有日志用户交互(操作调用),所以我做了一些搜索,我发现代理模式是这个工作人员的最佳方式,我的问题是在我的案例中,我如何使用Mobx和代理。 感谢的

1 个答案:

答案 0 :(得分: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}`);
  }
});