How to handle a dispatch related to an ES6 Map on the store?
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 312
- PR merge metrics
- No merged PRs in 30d
Description
Which is the "correct" way to change an ES6 Map on the store?
Note that `this.props.mapAlertsDoNotShowAgain` is coming from `AltContainer` as a reference to the related value in the altjs store.
_Version 1:_
(has a small performance hit due to the cloning)
```
const mapAlertsDoNotShowAgain = new Map(this.props.mapAlertsDoNotShowAgain);
mapAlertsDoNotShowAgain.set(mapAlertType, 3);
uiActions.changeValue({
which: 'mapAlertsDoNotShowAgain',
value: mapAlertsDoNotShowAgain,
});
```
OR
_Version 2:_
(mutates the reference and then does the action, we do not clone as the end result will be the same... or NOT?)
```
this.props.mapAlertsDoNotShowAgain.set(mapAlertType, 3);
uiActions.changeValue({
which: 'mapAlertsDoNotShowAgain',
value: mapAlertsDoNotShowAgain,
});
```
In other words, should we always clone an Array, Object, Map in order to change one of their values through an action? Or we can just mutate their reference _and_ then send the action?
Thanks for the clarification.
Contributor guide
Research direction
Start by comparing the two Map-update examples in the issue and trace how AltContainer supplies the store value and how uiActions.changeValue consumes it. Review the surrounding store and action behavior to determine whether cloning or reference mutation is supported, then document the recommended approach for Maps, Arrays, and Objects.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100