ComposableDuck

ComposableDuck

ComposableDuck提供Duck的组合功能,按路径(route)整合到state树中

注意:ducks的route不能与ComposableDuck自身的reducers key重复

ComposableDuck.prototype.ducks

根据duck.quickDucks和duck.rawDucks生成的map,可以通过它访问子duck

class FooDuckMap extends ComposableDuck {
  get reducers() {
    return {
      ...super.reducers,
      foo() {
        return 1;
      }
    };
  }
  get quickDucks() {
    return {
      ...super.quickDucks,
      foo1: FooDuck
    };
  }
  get rawDucks(){
      return {
          ...super.rawDucks,
          foo2: new FooDuck(this.getSubDuckOptions('foo2'))
      }
  }
  *saga() {
    yield* super.saga();
    const {selector, ducks} = this
    const state = selector(yield select())
    state.foo
    state.foo1.foo
    ducks.foo2.types.FOO
  }
}

Last updated