angular-redux / form

Keep your Angular2+ form state in Redux
MIT License
41 stars 15 forks source link

Two actions fired on every form value change, the second overwriting the first. #28

Closed artparks closed 7 years ago

artparks commented 7 years ago

This is a...

What toolchain are you using for transpilation/bundling?

Environment

NodeJS Version: 7.8.0 Typescript Version: 2.2.2 Angular Version: 4.2.2 @angular-redux/store version: 6.4.5 @angular/cli version: 1.0.6 OS: mac os

Link to repo showing the issue

https://github.com/artparks/forms-actions

Expected Behaviour:

Just one action to be fired when the forms are updated

Actual Behaviour:

Two actions are fired, one with the payload set correctly to the new state of the input, then immediately another one after this whose payload is the previous state.

Stack Trace/Error Message:

n.a

Additional Notes:

I've replicated the setup shown in the example repo, but cannot prevent this issue. It seems that when the this.form.valueChanges callback is fired in connect.ts, the action published causes this observable to immediately fire again. If I remove the call to publish the action in the callback, it only fires once. I assume when the field is updated via NgModel this causes the second firing of the action. I cannot see why this is happening or how to prevent it, especially when this example is so similar to the example that does work.

el-davo commented 7 years ago

Am also seeing this error. Have you found any workaround? Here is a screenshot, I add the letter "D" to the "name" field and it fires twice

image

rdinicut commented 7 years ago

You did not compose a reducer for the form.

const rootreducer = composeReducers(
  defaultFormReducer(),
  combineReducers({
    foo: fooReducer,
    bar: barReducer
  })
);
artparks commented 7 years ago

Yep, sorted. Thanks.