ngrx-forms icon indicating copy to clipboard operation
ngrx-forms copied to clipboard

Pattern: Supply different "feature state" into the form reducer?

Open mostl33 opened this issue 3 years ago • 1 comments
trafficstars

Hi there,

first: a thanks for this great library! it really save a lot of tedious work.

Is there a good pattern on how to get the state of another feature (= different ngrx feature module with a form) into the form reducer? I am working on a "rent" calculator which needs certain form values from another (different feature module) form to calculate another form field.

Thanks,

Lee

mostl33 avatar Jun 23 '22 14:06 mostl33

I would say you can use an effect in between.

  1. You dispatch an action with the info you currently have in the payload.
  2. An effect can use withLatestFrom to grab the info you need from the other module.
  3. The effect dispatches a new action with all the that you need (previous payload + state data you just read).
  4. Form reducer receives the second action and you have all the data you need.

Balastrong avatar Jul 25 '22 18:07 Balastrong