reactjsreduxredux-observable

Polling redux epic until condition is met


Hello awesome community,

I am working on a polling redux epic that should keep firing an action until a condition is met. This condition is based on the response of the action.

It turns out that polling is possible and I should add a cancellation action: takeUntil(actions$.pipe(ofType(CANCEL))). However, I am trying to implement the following with no cancel action:

      timer(0, x * 1000).pipe(
        takeUntil(response.element.available === true),
......

This is firing the error: ```Argument of type 'boolean' is not assignable to parameter of type 'ObservableInput'````

Is what I am looking to implement not possible? (Does it break the redux logic?)?

Thank you in advance for your help!


Solution

  • takeUntil takes an ObservableInput as its argument. You have passed a boolean, as that condition `response.element.available === true is evaluated when that code is first run.

    Create an observable that emits when that condition is true and pass that in.