web:javascript:angular:ngrx
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
web:javascript:angular:ngrx [2018/10/06 17:42] – [Composition de l'état par module] sgariepy | web:javascript:angular:ngrx [2022/02/02 00:42] (Version actuelle) – modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 196: | Ligne 196: | ||
) { } | ) { } | ||
- | // tslint: | ||
@Effect() loadCompanies$ = this.actions$ | @Effect() loadCompanies$ = this.actions$ | ||
.ofType(companyActions.LOAD_COMPANIES) | .ofType(companyActions.LOAD_COMPANIES) | ||
Ligne 204: | Ligne 203: | ||
}); | }); | ||
- | // tslint: | ||
@Effect() deleteCompany$ = this.actions$ | @Effect() deleteCompany$ = this.actions$ | ||
.ofType(companyActions.DELETE_COMPANY) | .ofType(companyActions.DELETE_COMPANY) | ||
Ligne 212: | Ligne 210: | ||
}); | }); | ||
}; | }; | ||
+ | </ | ||
+ | |||
+ | |||
+ | < | ||
+ | @Effect({ dispatch: false }) | ||
+ | </ | ||
+ | |||
+ | Lancer une seule requête lors de plusieurs appels d' | ||
+ | |||
+ | <code javascript> | ||
+ | @Effect() | ||
+ | request$: Observable< | ||
+ | ofType< | ||
+ | distinct( | ||
+ | () => RequestTypes.REQUEST_FETCH, | ||
+ | this.actions$.pipe( | ||
+ | ofType< | ||
+ | RequestTypes.REQUEST_SUCCESS, | ||
+ | RequestTypes.REQUEST_FAILED | ||
+ | ) | ||
+ | ) | ||
+ | ), | ||
+ | mergeMap(action => | ||
+ | this.someService.request(action.data).pipe( | ||
+ | map(data => { | ||
</ | </ | ||
Ligne 228: | Ligne 251: | ||
- | ====== Dispatching | + | ====== Dispatching |
+ | Le // | ||
+ | |||
+ | <code javascript> | ||
+ | constructor(private store: Store< | ||
+ | </ | ||
+ | |||
+ | Par la suite, on peut lancer des actions: | ||
+ | |||
+ | <code javascript> | ||
+ | this.store.dispatch(new ProductsFetch()); | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ====== Sélecteurs ====== | ||
+ | |||
+ | L' | ||
+ | |||
+ | <code javascript> | ||
+ | interface IRequestState { | ||
+ | pending: boolean; | ||
+ | success: boolean; | ||
+ | error: any; | ||
+ | } | ||
+ | |||
+ | export const someRequestSelector: | ||
+ | AppSelectors.appSelector(), | ||
+ | (state: any) => state && state.someRequest | ||
+ | ); | ||
+ | |||
+ | export const requestSuccess: | ||
+ | IHttpState, | ||
+ | boolean | ||
+ | > = createSelector( | ||
+ | someRequestSelector, | ||
+ | (request: IRequestState) => request && request.success | ||
+ | ); | ||
+ | </ | ||
+ | Le sélecteur '' | ||
+ | * [[https:// | ||
Ligne 238: | Ligne 302: | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// |
web/javascript/angular/ngrx.1538840530.txt.gz · Dernière modification : 2022/02/02 00:43 (modification externe)