如何将Flux存储迁移到Redux?

时间:2017-01-19 01:26:01

标签: javascript redux flux migrate riot.js

如何开始将我的Flux商店移植到Reducer以使用redux?我想慢慢地这样做而不会破坏应用程序的其余部分。

我已经阅读了Redux提供的有关迁移的所有文献: http://redux.js.org/docs/recipes/MigratingToRedux.html

然而,它看起来非常模糊。我的商店是基地商店的扩展:

import EventEmitter from 'events';

const CHANGE_EVENT = 'change';

class BaseStore extends EventEmitter {

  constructor() {
    super();
  }

  emitChange() {
    this.emit(CHANGE_EVENT);
  }

  addChangeListener(callback) {
    this.on(CHANGE_EVENT, callback);
  }

  removeChangeListener(callback) {
    this.removeListener(CHANGE_EVENT, callback);
  }

}

export default BaseStore;

以下是实际商店的示例:

import Constants from '../constants';
import dispatcher from '../scripts/dispatcher';
import BaseStore from './base';

class ExampleStore extends BaseStore {

  constructor() {
    super();
    this.exampleProperty = false;

    this.dispatchToken = dispatcher.register((payload) => {

      switch (payload.actionType) {

        case Constants.Example.EXAMPLE_CONSTANT:
          this.exampleProperty = !this.exampleProperty;
          this.emitChange();
          break;

        default:
          // no-op
      }

    });
  }

}

export default new ExampleStore();

0 个答案:

没有答案