ngrx Load data from server only if the store is empty

前端 未结 4 1319
离开以前
离开以前 2021-01-01 15:19

I have a static set of data, a list of countries, that are used on some components. This data is loaded upon the ngOnInit() of these components but I\'d like to

4条回答
  •  余生分开走
    2021-01-01 15:36

    You can select the countries from the store within effects, if they are represented in the store we ignore the action, if not we fetch the countries.

    @Effect()
    getOrder = this.actions.pipe(
      ofType(ActionTypes.GetOrder),
      withLatestFrom(this.store.pipe(select(getOrders))),
      filter(([{payload}, orders]) => !!orders[payload.orderId])
      mergeMap([{payload}] => {
        ...
      })
    )
    

    For more info see Start using ngrx/effects for this.

提交回复
热议问题