redux-fork

0.1.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i redux-fork

Weekly Downloads

2

Version

0.1.1

License

MIT

Last publish

Collaborators

  • weo-edu