@duckness/epic
Version:
Redux-Observable extension for @duckness/duck - Modular Redux Ducks hatchery
102 lines (78 loc) • 4.96 kB
Markdown
# `/epic` <!-- omit in toc -->
[Redux-Observable](https://redux-observable.js.org/) extension for [@duckness/duck](https://github.com/hitosu/duckness/tree/master/packages/duck)
[](https://www.npmjs.com/package/@duckness/epic)
[](https://github.com/hitosu/duckness/blob/master/LICENSE)
[](https://www.npmjs.com/package/@duckness/epic?activeTab=dependencies)
[](https://github.com/hitosu/duckness/issues)
[](https://github.com/hitosu/duckness/issues)
[](https://www.npmjs.com/package/@duckness/epic)
# Example
```js
// counterDuck.js
import EpicDuck from '/epic'
import { map, delay } from 'rxjs/operators'
import { ofType } from 'redux-observable'
// Create duck with the name 'counter' for 'counter-app' app
const counterDuck = EpicDuck('counter', 'counter-app')
// Add actions
counterDuck.action('increment', 'INCREMENT')
counterDuck.action('incrementAsync', 'INCREMENT_ASYNC')
// add epic
counterDuck.epic(function incrementAsync(action$, state$, duckFace) {
return action$.pipe(
ofType(duckFace.actionTypes.INCREMENT_ASYNC),
delay(1000),
map(action => duckFace.action.increment(action.payload))
)
})
// root epic
export const rootEpic = counterDuck.rootEpic
```
# Table of Contents <!-- omit in toc -->
- [Example](#example)
- [API](#api)
- [Epic](#epic)
- [`.epic(epic)`](#epicepic)
- [`.rootEpic`](#rootepic)
- [Error reporter](#error-reporter)
- [`.setErrorReporter`](#seterrorreporter)
- [`.reportError(error)`](#reporterrorerror)
- [ packages:](#duckness-packages)
# API
`EpicDuck` extends `duckness` `Duck`
## Epic
### `.epic(epic)`
Adds a new epic to the duck
```js
myDuck.epic(function myEpic(action$, state$, duckFace) { /*...*/ })
```
### `.rootEpic`
Duck's root epic with epics isolation (exceptions in one epic will not break other epics).
```js
myDuck.rootEpic
```
## Error reporter
### `.setErrorReporter`
Set error reporter (default is `console.error`) that reports uncatched epic errors
```js
myDuck.setErrorReporter(error => {
window.Sentry.captureException(error)
})
```
### `.reportError(error)`
Call assigned error reporter
```js
myDuck.reportError(new Error('Clean duck!'))
```
# packages:
* [/duck](https://github.com/hitosu/duckness/tree/master/packages/duck) - [Modular Redux Ducks](https://github.com/erikras/ducks-modular-redux) hatchery
* [/saga](https://github.com/hitosu/duckness/tree/master/packages/saga) - [Redux Saga](https://redux-saga.js.org/) extension for [/duck](https://github.com/hitosu/duckness/tree/master/packages/duck)
* [/epic](https://github.com/hitosu/duckness/tree/master/packages/epic) - [Redux-Observable](https://redux-observable.js.org/) extension for [/duck](https://github.com/hitosu/duckness/tree/master/packages/duck)
* [/pool](https://github.com/hitosu/duckness/tree/master/packages/pool) - [@duckness/duck](https://github.com/hitosu/duckness/tree/master/packages/duck) + [Redux](https://redux.js.org/)
* [/pool-saga-stream](https://github.com/hitosu/duckness/tree/master/packages/pool-saga-stream) - [@duckness/saga](https://github.com/hitosu/duckness/tree/master/packages/saga) plugin for [@duckness/pool](https://github.com/hitosu/duckness/tree/master/packages/pool)
* [/pool-epic-stream](https://github.com/hitosu/duckness/tree/master/packages/pool-epic-stream) - [@duckness/epic](https://github.com/hitosu/duckness/tree/master/packages/epic) plugin for [@duckness/pool](https://github.com/hitosu/duckness/tree/master/packages/pool)
* [/react-redux-pool](https://github.com/hitosu/duckness/tree/master/packages/react-redux-pool) - [@duckness/pool](https://github.com/hitosu/duckness/tree/master/packages/pool) + [React-Redux](https://react-redux.js.org/)
* [/use-redux](https://github.com/hitosu/duckness/tree/master/packages/use-redux) - [React hook](https://reactjs.org/docs/hooks-intro.html) for [Redux](https://react-redux.js.org/) store
* [/use-pool](https://github.com/hitosu/duckness/tree/master/packages/use-pool) - [React hook](https://reactjs.org/docs/hooks-intro.html) for [@duckness/pool](https://github.com/hitosu/duckness/tree/master/packages/pool).
* [/store](https://github.com/hitosu/duckness/tree/master/packages/store) - simple store for [React](https://reactjs.org/) components
* [/reactor](https://github.com/hitosu/duckness/tree/master/packages/reactor) - reactive data flow builder