-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to avoid infinit self calls #24
Comments
I try to fix it by rewrite some souce code as follow, but I dont known if it has some bad side effects or not from: Line 194 in b7b644b
to: const payload$ = new BehaviorSubject<any>(undefined)
actions[actionName] = (payload: any) => {
payload$.next(payload)
}
const effect$: Observable<EffectAction> = from(Promise.resolve()).pipe(
switchMap(() => effectActions[actionName](payload$, state$))
) |
@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)),
)
} I think that the issue is caused by the @Effect()
fetchInfo(url$: Observable<string>):Observable<EffectAction> {
return url$.pipe(
switchMap(url => from(client.get(url))),
mergeMap(data => of(
this.getActions().setLoading(true),
this.getActions().setData(data),
this.getActions().setLoading(false)
)),
)
} Maybe we should show some tips about misuse the |
@runjuu @Effect()
fetchInfo(url$: Observable<string>):Observable<EffectAction> {
this.getState() // Error
this.getState$() // Error
this.getActions() // Error
return url$.pipe(
switchMap(url => from(client.get(url))),
mergeMap(data => of(
this.getActions().setLoading(true),
this.getActions().setData(data),
this.getActions().setLoading(false)
)),
)
} or we can do something avoid this error ? |
if we invoke else service method suck as
this.getActions()
inside theeffectActions[actionName]
function in sync way, it will cause an error:the effect can be:
the effect init function is :
ayanami/src/core/ikari.ts
Line 196 in b7b644b
because the
startWith
is sync, sothis.getActions()
will request theikari
instance, but the ikari instance is not fully constructed at that time. so it will invoke the create function again and agian...The text was updated successfully, but these errors were encountered: