4 ms·
I haven't seen anything about this in my research other than the obligatory "globals r bad nub do not use dis evr 1337" Not to say that's wrong, just that I'm
by LiterallyDoge 8y ago
I haven't seen anything about this in my research other than the obligatory "globals r bad nub do not use dis evr 1337"
Not to say that's wrong, just that I'm lacking on concrete rationale. If you get a few minutes, would you be kind enough to link me to further reading on maybe some of the ways Vuex provides a better approach than traditional globals in singleton namespaces? (Or just post here but I don't want to ask you to explain something that's already well documented)
Thanks for your help either way, really appreciate your time.
- cimmanom 8y agoGlobals make it really difficult to test, reuse, or repurpose code. And you can only ever have one instance of a given global, so if you want multiple instances of your widget you face really ugly refactoring. If you google for it there should be plenty of good resources on this topic. It sounds like maybe you’re relatively new to programming - it only takes running into this situation once to start to understand the reasons for avoiding them. They’re especially dangerous in JavaScript because of the way it handles scoping. If you accidentally miss a “var” or “let” inside a function you could find yourself mutating global instead of local data. Vuex lets you scope your data to a module. It also as I described above lets you limit mutations to a known set of operations, which becomes important in a large or long-lived codebase.
- LiterallyDoge 8y agoThanks good points I'll keep at the research.