0.1.1 • Published 8 years ago

redux-fork v0.1.1

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

fork

Build status Git tag NPM version Code style

Redux effects support for non blocking async calls.

Installation

$ npm install fork

Usage

import forkEffect, {fork, join} from 'redux-fork'

const store = applyMiddleware(flo(), forkEffect)(createStore)(reducer, {})

function * child () {
  yield delay(5)
  return 'foo'
}

store.dispatch(function * () {
  const task = yield fork(child)

  // do some things

  yield join(task) // => 'foo'

})

API

fork(fn)

Action creator.

  • fn - function, generator, or iterator to fork

Returns: a task

join(task)

Action creator.

  • task - task to block on

Returns: result of task

cancel(task)

Action creator. Throws error in running task with message: 'TaskCanceled'.

  • task - task to cancel

taskRunner(dispatch)

Runs tasks. Used internally by koax.

  • dispatch - dispatch function

Returns: dispatch

task.isRunning()

Returns: whether task is running

task.result()

Returns: the result of the task

task.error()

Returns: the error thrown by the task

###task.cancel() Cancels task

License

MIT