Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

Latest commit

 

History

History
33 lines (24 loc) · 1.2 KB

redux-observable.md

File metadata and controls

33 lines (24 loc) · 1.2 KB

redux-observable

redux-observables can be used to manage side effects via Epics (their core primitive to receive and create stream of actions). Subspace can be configured inside these epics.

It's recommended to compose these epics by using mergeMap or switchMap operators.

Here's an example on how to use Subspace to subscribe to an Event when the action SOME_ACTION is dispatched, and then it will trigger myAction when the observable emits a value.

// ...

const myEpic = action$ =>
  action$.pipe(
    ofType("SOME_ACTION"),  // Execute when the action type is 'INIT'
    switchMap(action =>
      subspace
        .trackEvent(MyContract, "MyEventName", { filter: {}, fromBlock: 1})
        .pipe(
          map(myAction) // Trigger redux action: MY_ACTION with the eventData
        )
    )
  );

// ...

::: tip An example is available in Github :::

Further read