8000 How to handle a dispatch related to an ES6 Map on the store? · Issue #662 · goatslacker/alt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
How to handle a dispatch related to an ES6 Map on the store? #662
Open
@afilp

Description

@afilp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0