Skip to content

4.1.2

Compare
Choose a tag to compare
@e-oz e-oz released this 13 Aug 09:19
· 9 commits to main since this release

Improved API for createEffect() listeners, introduced in v4.1.1.

Methods of the function, returned by createEffect():

export type EffectFnMethods = {
  next: (fn: ((v: unknown) => void)) => void,
  error: (fn: ((v: unknown) => void)) => void,
  complete: (fn: (() => void)) => void,
  next$: Observable<unknown>,
  error$: Observable<unknown>,
};

Also, you can set next listener or an object with listeners as a second argument, when you call an effect:

class Component {
  store = inject(Store);
  dialog = inject(Dialog);
  toasts = inject(Toasts);
  
  changeZipCode(zipCode: string) {
    this.store.changeZipCode(zipCode, () => this.dialog.close());
    
    // or:
    this.store.changeZipCode(zipCode, {
      next: () => this.dialog.close(),
      error: () => this.toasts.error('Error, please try again.'),
    });
  }
}