3 ms·
You see something is flawed in Redux at the point you have to pass strings (uppercase constants defined somewhere) around, import them in every file, pass them
by fiatjaf 10y ago
You see something is flawed in Redux at the point you have to pass strings (uppercase constants defined somewhere) around, import them in every file, pass them as identifiers of what you should do with each data.
- catshirt 10y agoif you use redux-actions your reducer can use an action reference directly- not its "type" string. developing this way I don't need to store references to these "constants" and they're only ever relevant when logging.
- joshwcomeau 10y agoYou don't actually have to do this if it bothers you. You can just use the strings inline, but the author (and many of those using Redux) finds it helps to reduce errors, by instantly pointing out typos. There are also patterns to reduce the import issue. For example, https://github.com/erikras/ducks-modular-redux https://github.com/erikras/ducks-modular-redux. I prefer defining my actions with my action creators in one big index, but the point is that there is absolutely a way to mitigate this concern if it bothers you :)
- fiatjaf 10y ago> You can just use the strings inline Well, that would be much worse, don't you think? My point was that having to keep identifiers to everything is silly.
- shriek 10y agoThe point of keeping identifiers is to show you the intents of an action. If any identifiers seem silly to be added then maybe they don't deserve to be going through reducers in the first place.
- rexpop 10y agoWhy is it flawed to use the module system to enforce references?
- ezpg 10y agoUse Symbols instead of Strings: https://www.keithcirkel.co.uk/metaprogramming-in-es6-symbols/ https://www.keithcirkel.co.uk/metaprogramming-in-es6-symbols... See the second line of the code snippet under "Symbols are completely unique…" Unless I have misunderstood the spec, to compare symbols you require both the reference and value. Much more preferable than passing around Strings.
- acemarke 10y agoYou _can_ use Symbols for `action.type` in Redux, but that's discouraged, because they're not serializable and thus will not work properly with time-travel debugging. See http://redux.js.org/docs/faq/Actions.html#actions-string-constants http://redux.js.org/docs/faq/Actions.html#actions-string-con... .