DuckRuntime

从Duck实例创建Redux store并运行sagas,提供与React组合的功能。

constructor(duck, ...middlewares)

  • duck Duck实例
  • middlewares Redux Store中间件
import { DuckRuntime } from 'saga-duck'
import { createLogger } from 'redux-logger'

const myDuck = new MyDuck(...)
const duckRuntime = new DuckRuntime(myDuck, createLogger({collapsed: true}))

connectRoot(): Decorator

const ConnectedContainer = duckRuntime.connectRoot()(
    Container
)

// decorator写法
@duckRuntime.connectRoot()
function Container(){...}

等效于

// 传统写法
const ConnectedContainer = duckRuntime.connect()(
    duckRuntime.root()(
        Container
    )
)

// decorator写法
@duckRuntime.connect()
@duckRuntime.root()
function Container(){...}

connect(): Decorator

与Redux store关联,功能同react-redux的connect

root(): Decorator

关联React,在mount时触发INIT动作,unmount时触发END动作,详见

addSaga(sagas): void

动态添加sagas到运行环境中(立即执行),注意此时添加的与任何duck都无关联,即不会传duck作为入参。

duckRuntime.addSagas([function*(){  }])

results matching ""

    No results matching ""