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
        )
    )
  );

// ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

An example is available in Github

Further read