ImmutableUtil store state is reset when dispatching initial action on store
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 312
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I am experiencing an issue where my store is getting reset back to its default state (as defined in the constructor) when firing an initial action on the client. The store is using the `ImmutableUtil` decorator, and upon inspecting the initial bootstrapped data from the server, everything is fine. However, when I dispatch an action on the client, the state is reset. It's worth mentioning that I am not even attempting yet to change the store's state using `this.setState()`.
Component method firing the action:
``` javascript
onSearchInputChange(evt) {
require('debug')('dev')('onSearchInputChange', this.context.flux.stores.numberAllocations.state.toString());
this.context.flux.getActions('numberAllocations')
.updateFilter({ key: 'dialledNumber', value: evt.target.value });
}
```
The store:
``` javascript
import Immutable from 'immutable';
import immutableStore from 'alt/utils/ImmutableUtil';
import _trimLeft from 'lodash/string/trimLeft';
@immutableStore
export default class NumberAllocationsStore {
constructor() {
this.bindActions(this.alt.getActions('numberAllocations'));
this.state = new Immutable.Map({
data: new Immutable.List([]),
meta: new Immutable.Map({}),
filters: new Immutable.Map({
dialledNumber: ''
}),
dataCurrentAllocation: new Immutable.Map({})
});
}
onRetrieveAllocations({ data, meta }) {
this.setState(this.state.merge({ data, meta }));
}
onRetrieveAllocation(data) {
this.setState(this.state.set('dataCurrentAllocation', data));
}
onUpdateFilter({ key, value }) {
require('debug')('dev')('onUpdateFilter', key, value, this.state.toString());
}
}
```
To demonstrate this - the console output in `onSearchInputChange` (ran just before dispatching the action) is fine, while the console output for `onUpdateFilter` returns the unwanted reset store state:

I'm really quite stuck with this one. :confused: Alt version is 0.17.8. Any help would be greatly appreciated!
Contributor guide
Assessment
This issue has not been assessed yet.