Open afilp opened 8 years ago
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.
this.props.mapAlertsDoNotShowAgain
AltContainer
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.
Which is the "correct" way to change an ES6 Map on the store?
Note that
this.props.mapAlertsDoNotShowAgain
is coming fromAltContainer
as a reference to the related value in the altjs store.Version 1: (has a small performance hit due to the cloning)
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?)
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.