Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.

actions.reset sets model value to undefined #561

Closed
jameshy opened this issue Dec 7, 2016 · 6 comments
Closed

actions.reset sets model value to undefined #561

jameshy opened this issue Dec 7, 2016 · 6 comments
Labels

Comments

@jameshy
Copy link
Contributor

jameshy commented Dec 7, 2016

When I have a model like this:

{
    user: {
        anArray: []
    }
}

Calling actions.reset('user') multiple times results in anArray to become undefined.

Here is a gist that shows the problem (1.3.2):
https://esnextb.in/?gist=774e09eda300aa56313d2718790e8334

The same gist without the problem (1.0.6)
https://esnextb.in/?gist=df83817a62cf98bb22dcc6bb7473a498

Clicking 'Reset Form' multiple times will cause the model array to become undefined.

@davidkpiano davidkpiano added the bug label Dec 7, 2016
@davidkpiano
Copy link
Owner

Does this also occur for you in 1.4.0 by any chance?

@lasergoat
Copy link
Contributor

lasergoat commented Dec 10, 2016

@davidkpiano this is 90% for sure the same issue I'm having.

I have store.payment which contains a meta.lineItems. lineItems is an array and is the only model affected by this bug. The rest of payment and payment.meta is reset correctly.

However, for each key of payment.meta.lineItems[0] a rrf/change is dispatched with no value thus clearing that key completely from the array.

      dispatch(actions.reset('payment')),

Which results in these actions being dispatched somehow:

Console LOG

However, if I switch my reset out for a change to the initialPayment object (the same object used in creating the form reducer, my problem is solved.

      dispatch(actions.change('payment', initialPayment)),

(@jameshy you can use that as a workaround for now also... instead of a reset, just change it to the initial on your own.)

Problem occurs in versions:

  • 1.3.2
  • 1.4.0
  • 1.4.1

I don't have time to test each version but:

v1.0.15 works just fine!

@agustingp
Copy link

@davidkpiano I am using version 1.14.1 and I am having the same issue @lasergoat had: I have store.sites[] and when dispatch(actions.reset(sites[0])) the key is updated in the model with undefined value.

@davidkpiano
Copy link
Owner

@agustingp That should be expected behavior - consider a non-empty array with more than one element. Choosing to reset a single value should result in, e.g., [undefined, 1, 2, 3, 4].

@agustingp
Copy link

@davidkpiano thank you for answering! So, how can I do to reset (setting its initial value) the model of an object stored inside the array?

@davidkpiano
Copy link
Owner

If the array has dynamically loaded values, with actions.load('model.array[0]', 'something'), it should naturally reset to that 'something' as the initial value. If it doesn't, please open a separate ticket and I'll look at it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants