Integrating Custom Effects
Whats mine is yours, whats yours is mine!
Custom Action
export const SearchCustomers = createAction(
'[Customer] Typeahead Search',
props<{criteria: string }>()
);Custom Effect
import {Actions, createEffect} from '@ngrx/effects';
import {LoadAllSuccess, LoadAllFailure} from '@briebug/ngrx-auto-entity';
import {SearchCustomers} from 'state/customer.actions';
export class CustomerEffects {
searchCustomers$ = createEffect(
() => this.actions$.pipe(
ofType(SearchCustomers),
map(action => action.criteria),
switchMap(criteria =>
this.customerService.search(criteria).pipe(
map(result => new LoadAllSuccess(Customer, result)),
catchError(err => of(new LoadAllFailure(Customer, err)))
)
)
),
{ resubscribeOnError: false }
);
constructor(private actions$: Actions, private customerService: CustomerService) {}
}Integrate into Auto-Entity Managed State
Last updated