Skip to content

Conversation

@zivl
Copy link

@zivl zivl commented Oct 13, 2015

In case where multiple classes are using the same String keys, there is
no way to distinct between one an other. With JavaScript Symbol
mechanism it is possible and it is still easy to debugץ

Common Example, when using FLUX architecture:

SomeStore.dispatchToken = AppDispatcher.register(function (action) {

    switch (action.actionType) {
        case ConstantsA.READY:
            // do something...
            break;
        case ConstantsB.READY:
            // do something else...
            break;
        default:
            // default

    }
});

In case where multiple classes are using the same String keys, there is
no way to distinct between one an other. With JavaScript Symbol
mechanism it is possible and it is still easy to debug
@vasco3
Copy link

vasco3 commented Oct 13, 2015

I stopped using keyMirror since we have Symbol() in ES6

@zivl
Copy link
Author

zivl commented Oct 14, 2015

do you mean something like this?

const keys = {
    READY: Symbol('READY'),
    DONE: Symbol('DONE')
};

export default keys;

@vasco3
Copy link

vasco3 commented Oct 15, 2015

yeah, or simply

const keys = {
    READY: Symbol(),
    DONE: Symbol()
};

export default keys;

@sheerun
Copy link

sheerun commented Oct 23, 2015

@vasco3 Redux documentation says:

It’s better to use strings for type than Symbols because strings are serializable.

Any comment on this?

@vasco3
Copy link

vasco3 commented Oct 24, 2015

@sheerun not sure which would be the advantage on strings vs Symbols. But React doesn't marks it as warning so I think it's fine. Might be an issue with rendering to static HTML eg. for server-side rendering.

@zivl
Copy link
Author

zivl commented Oct 24, 2015

I have a solution which can satisfied both opinions:
maybe I'll add it as a configurable parameter whether the mirroring will put a string of a Symbol.
What do you think?

@vasco3
Copy link

vasco3 commented Oct 25, 2015

well you would have to transpile this npm module before publishing, so the Symbol might be converted to something redundant with keyMirror with the polyfill used by the transpiler...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants