Как выполнить водопад angular действий или эффектов, когда результат предыдущего действия или эффекта определяет следующий шаг - PullRequest
0 голосов
/ 01 августа 2020

У меня есть следующие эффекты

  /**
   * Step 1: This action triggers a data flush
   */
  @Effect()
  loadStripeForUse$ = this._actions$.pipe(
    ofType<LoadStripeForUse>(EStripeActions.LoadStripeForUse),
    map( () => new PreLoadStripeAPIDataClear())
  );

  /**
   * Step 2: This action handles a data flush and triggers API request for
   * stripe keys
   */
  @Effect()
  preLoadStripeAPIDataClear$ = this._actions$.pipe(
    ofType<PreLoadStripeAPIDataClear>(EStripeActions.PreLoadStripeAPIDataClear),
    concatMap(() => [
      new PreLoadStripeAPIDataClearSuccess(),
      new PostCreateStripePaymentIntentKeys()
    ])
  );

  /**
   * Step 3: Grab Stripe keys then save keys and pass keys onto call for Stripe API
   */
  @Effect()
  postCreateStripePaymentIntentKeys$ = this._actions$.pipe(
    ofType<PostCreateStripePaymentIntentKeys>(EStripeActions.PostCreateStripePaymentIntentKeys),
    switchMap((action) => this._restApiService.stripeCreateStripePaymentIntentKeysPost()),
    concatMap( (payload: IStripePaymentIntentKeys) => [
      new PostCreateStripePaymentIntentKeysSuccess(payload),
      new LoadStripeApi(payload)
    ])
  );

  /**
   * Step 4: Load Stripe API with keys then store Stripe API in store for use
   */
  @Effect()
  loadStripeApi$ = this._actions$.pipe(
    ofType<LoadStripeApi>(EStripeActions.LoadStripeApi),
    switchMap((action) => this._restApiService.loadStripe(action.payload.public_key)),
    concatMap ( (stripe: Stripe) => [
      new LoadStripeApiSuccess(stripe),
      new LoadStripeForUseSuccess(stripe)
    ])
  );

В идеале я хотел бы иметь возможность, чтобы каждый эффект обрабатывал свои собственные функции и объединял их все в один эффект, где они падают. Примерно так к следующему действию / эффекту и так далее. Как этого добиться?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...