Skip to content

How to avoid infinit self calls #24

Open
@stkevintan

Description

@stkevintan

if we invoke else service method suck as this.getActions() inside the effectActions[actionName] function in sync way, it will cause an error:

InternalError: "too much recursion"

the effect can be:

  @Effect()
  fetchInfo(url$: Observable<string>):Observable<EffectAction> {
    return url$.pipe(
      switchMap(url => from(client.get(url))),
      mergeMap(data => of(this.getActions().setData(data), this.getActions().setLoading(false))),
      startWith(this.getActions().setLoading(true)),
    )
  }

the effect init function is :

const effect$: Observable<EffectAction> = effectActions[actionName](payload$, state$)

because the startWith is sync, so this.getActions() will request the ikari instance, but the ikari instance is not fully constructed at that time. so it will invoke the create function again and agian...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions