Why doesn't (Flux) state management use static functions instead of named properties









up vote
4
down vote

favorite












I'm currently deciding between switching to react.js or vue.js from angularJS . The goal is to use it including Typescript to make sure that everything is Typesafe.



With trying out vuex and redux I have noticed that they don't use normal functions but instead use some form of string naming for functions.



Redux for example checks via a switch in reducers for a certain function
Image 1



Vuex uses constant objects where the functions in that object can be called via functions which take a string and a payload



Image 2Image 3



What is the reason for this? Somehow this feels like it's going to be painful when you have to refactor and feels like a way to make mistakes while programming because of typo's.



Why wouldn't a normal class with static functions do the job(or another perhaps better solution)
Image 4










share|improve this question



























    up vote
    4
    down vote

    favorite












    I'm currently deciding between switching to react.js or vue.js from angularJS . The goal is to use it including Typescript to make sure that everything is Typesafe.



    With trying out vuex and redux I have noticed that they don't use normal functions but instead use some form of string naming for functions.



    Redux for example checks via a switch in reducers for a certain function
    Image 1



    Vuex uses constant objects where the functions in that object can be called via functions which take a string and a payload



    Image 2Image 3



    What is the reason for this? Somehow this feels like it's going to be painful when you have to refactor and feels like a way to make mistakes while programming because of typo's.



    Why wouldn't a normal class with static functions do the job(or another perhaps better solution)
    Image 4










    share|improve this question

























      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      I'm currently deciding between switching to react.js or vue.js from angularJS . The goal is to use it including Typescript to make sure that everything is Typesafe.



      With trying out vuex and redux I have noticed that they don't use normal functions but instead use some form of string naming for functions.



      Redux for example checks via a switch in reducers for a certain function
      Image 1



      Vuex uses constant objects where the functions in that object can be called via functions which take a string and a payload



      Image 2Image 3



      What is the reason for this? Somehow this feels like it's going to be painful when you have to refactor and feels like a way to make mistakes while programming because of typo's.



      Why wouldn't a normal class with static functions do the job(or another perhaps better solution)
      Image 4










      share|improve this question















      I'm currently deciding between switching to react.js or vue.js from angularJS . The goal is to use it including Typescript to make sure that everything is Typesafe.



      With trying out vuex and redux I have noticed that they don't use normal functions but instead use some form of string naming for functions.



      Redux for example checks via a switch in reducers for a certain function
      Image 1



      Vuex uses constant objects where the functions in that object can be called via functions which take a string and a payload



      Image 2Image 3



      What is the reason for this? Somehow this feels like it's going to be painful when you have to refactor and feels like a way to make mistakes while programming because of typo's.



      Why wouldn't a normal class with static functions do the job(or another perhaps better solution)
      Image 4







      reactjs vue.js redux vuex state-management






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 8 at 17:19

























      asked Nov 8 at 16:37









      redlum

      443




      443






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          Both Redux and Vuex create a single store instance from declared set of modules, that is responsible for dispatching/committing registered actions/mutations that require type to be provided as a string value. While scaling the application, usage of actions/mutations becomes quite widespread and using plain strings will reduce state mutation predictability significantly.



          Using constants, such as:



          export const ADD_PORTFOLIO = 'ADD_PORTFOLIO'


          allows to list all available state mutations in a separate list-like file, thus providing clear understanding of possible changes, while avoiding typos inside store modules and allowing IDE and code editors to autocomplete or highlight invalid references to constant types. Which reduces debugging time and would not be possible with plain strings. It is not required, neither it is an invention of mentioned libraries. It works well with globally invoked events (e.g. Node EvenEmitter, Electron ipcRenderer, etc) for the same reasons.



          Both Redux and Vuex store state in plain objects and require their API to be defined as a functions (each with it's own architecture), that will be merged into a single store instance. This serves purpose of providing reactive updates on state changes, warnings when state is mutated outside of mutations or dispatched action/mutation is not registered. My opinion is that this approach is efficient in absence of type safety, which both libraries are initially meant to be used without.



          For example, in Vuex if you decide to call an action or mutation from another module, you would use dispatch (for actions) or commit (for mutations) with a type referenced as full path to the module:



          dispatch('profile/addPortfolio', payload, root: true )
          commit('profile/ADD_PORTFOLIO', payload, root: true )


          Meaning, that both invocations should be done with store instance methods and are expected to be registered on current store instance, rather than importing and invoking module's action or mutation directly.



          In case Typescript is integrated into the project, it is possible to use class-based structure or decorators for the store and it's modules. Again, classes will be compiled to match store library architecture, but enhances development experience.



          As for Vuex, following libraries are worth checking out for using with Typescript:



          • vue-property-decorator

          • vuex-module-decorators


          • vuex-class - a helper to use vuex decorators inside components

          TLDR
          Such architecture is defined by mentioned libraries for usage without type-safety, while still allowing reactivity and centralized state mutation. Constants help to ensure that actions/mutations are registered on store instance, increase predictability and provide autocomplete for code editors.






          share|improve this answer






















          • Hi MrBiscuit, Thanks a lot for the extensive explanation. What i dont yet understand thought is the fact that it must be an object with functions in it and reference to it through the function names as strings. Do you know what the plus side of it it or the reason to design it like this?
            – redlum
            Nov 8 at 20:15






          • 1




            Looking at source code of dispatch methods Redux, Vuex - not only do they validate and dispatch actions, but also notify all subscribers of state changes. Which is a Observer pattern. Also, such approach allows to create namespaces for actions/mutations, while keeping it all on a single store instance.
            – aBiscuit
            Nov 8 at 22:08











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53212227%2fwhy-doesnt-flux-state-management-use-static-functions-instead-of-named-proper%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote













          Both Redux and Vuex create a single store instance from declared set of modules, that is responsible for dispatching/committing registered actions/mutations that require type to be provided as a string value. While scaling the application, usage of actions/mutations becomes quite widespread and using plain strings will reduce state mutation predictability significantly.



          Using constants, such as:



          export const ADD_PORTFOLIO = 'ADD_PORTFOLIO'


          allows to list all available state mutations in a separate list-like file, thus providing clear understanding of possible changes, while avoiding typos inside store modules and allowing IDE and code editors to autocomplete or highlight invalid references to constant types. Which reduces debugging time and would not be possible with plain strings. It is not required, neither it is an invention of mentioned libraries. It works well with globally invoked events (e.g. Node EvenEmitter, Electron ipcRenderer, etc) for the same reasons.



          Both Redux and Vuex store state in plain objects and require their API to be defined as a functions (each with it's own architecture), that will be merged into a single store instance. This serves purpose of providing reactive updates on state changes, warnings when state is mutated outside of mutations or dispatched action/mutation is not registered. My opinion is that this approach is efficient in absence of type safety, which both libraries are initially meant to be used without.



          For example, in Vuex if you decide to call an action or mutation from another module, you would use dispatch (for actions) or commit (for mutations) with a type referenced as full path to the module:



          dispatch('profile/addPortfolio', payload, root: true )
          commit('profile/ADD_PORTFOLIO', payload, root: true )


          Meaning, that both invocations should be done with store instance methods and are expected to be registered on current store instance, rather than importing and invoking module's action or mutation directly.



          In case Typescript is integrated into the project, it is possible to use class-based structure or decorators for the store and it's modules. Again, classes will be compiled to match store library architecture, but enhances development experience.



          As for Vuex, following libraries are worth checking out for using with Typescript:



          • vue-property-decorator

          • vuex-module-decorators


          • vuex-class - a helper to use vuex decorators inside components

          TLDR
          Such architecture is defined by mentioned libraries for usage without type-safety, while still allowing reactivity and centralized state mutation. Constants help to ensure that actions/mutations are registered on store instance, increase predictability and provide autocomplete for code editors.






          share|improve this answer






















          • Hi MrBiscuit, Thanks a lot for the extensive explanation. What i dont yet understand thought is the fact that it must be an object with functions in it and reference to it through the function names as strings. Do you know what the plus side of it it or the reason to design it like this?
            – redlum
            Nov 8 at 20:15






          • 1




            Looking at source code of dispatch methods Redux, Vuex - not only do they validate and dispatch actions, but also notify all subscribers of state changes. Which is a Observer pattern. Also, such approach allows to create namespaces for actions/mutations, while keeping it all on a single store instance.
            – aBiscuit
            Nov 8 at 22:08















          up vote
          2
          down vote













          Both Redux and Vuex create a single store instance from declared set of modules, that is responsible for dispatching/committing registered actions/mutations that require type to be provided as a string value. While scaling the application, usage of actions/mutations becomes quite widespread and using plain strings will reduce state mutation predictability significantly.



          Using constants, such as:



          export const ADD_PORTFOLIO = 'ADD_PORTFOLIO'


          allows to list all available state mutations in a separate list-like file, thus providing clear understanding of possible changes, while avoiding typos inside store modules and allowing IDE and code editors to autocomplete or highlight invalid references to constant types. Which reduces debugging time and would not be possible with plain strings. It is not required, neither it is an invention of mentioned libraries. It works well with globally invoked events (e.g. Node EvenEmitter, Electron ipcRenderer, etc) for the same reasons.



          Both Redux and Vuex store state in plain objects and require their API to be defined as a functions (each with it's own architecture), that will be merged into a single store instance. This serves purpose of providing reactive updates on state changes, warnings when state is mutated outside of mutations or dispatched action/mutation is not registered. My opinion is that this approach is efficient in absence of type safety, which both libraries are initially meant to be used without.



          For example, in Vuex if you decide to call an action or mutation from another module, you would use dispatch (for actions) or commit (for mutations) with a type referenced as full path to the module:



          dispatch('profile/addPortfolio', payload, root: true )
          commit('profile/ADD_PORTFOLIO', payload, root: true )


          Meaning, that both invocations should be done with store instance methods and are expected to be registered on current store instance, rather than importing and invoking module's action or mutation directly.



          In case Typescript is integrated into the project, it is possible to use class-based structure or decorators for the store and it's modules. Again, classes will be compiled to match store library architecture, but enhances development experience.



          As for Vuex, following libraries are worth checking out for using with Typescript:



          • vue-property-decorator

          • vuex-module-decorators


          • vuex-class - a helper to use vuex decorators inside components

          TLDR
          Such architecture is defined by mentioned libraries for usage without type-safety, while still allowing reactivity and centralized state mutation. Constants help to ensure that actions/mutations are registered on store instance, increase predictability and provide autocomplete for code editors.






          share|improve this answer






















          • Hi MrBiscuit, Thanks a lot for the extensive explanation. What i dont yet understand thought is the fact that it must be an object with functions in it and reference to it through the function names as strings. Do you know what the plus side of it it or the reason to design it like this?
            – redlum
            Nov 8 at 20:15






          • 1




            Looking at source code of dispatch methods Redux, Vuex - not only do they validate and dispatch actions, but also notify all subscribers of state changes. Which is a Observer pattern. Also, such approach allows to create namespaces for actions/mutations, while keeping it all on a single store instance.
            – aBiscuit
            Nov 8 at 22:08













          up vote
          2
          down vote










          up vote
          2
          down vote









          Both Redux and Vuex create a single store instance from declared set of modules, that is responsible for dispatching/committing registered actions/mutations that require type to be provided as a string value. While scaling the application, usage of actions/mutations becomes quite widespread and using plain strings will reduce state mutation predictability significantly.



          Using constants, such as:



          export const ADD_PORTFOLIO = 'ADD_PORTFOLIO'


          allows to list all available state mutations in a separate list-like file, thus providing clear understanding of possible changes, while avoiding typos inside store modules and allowing IDE and code editors to autocomplete or highlight invalid references to constant types. Which reduces debugging time and would not be possible with plain strings. It is not required, neither it is an invention of mentioned libraries. It works well with globally invoked events (e.g. Node EvenEmitter, Electron ipcRenderer, etc) for the same reasons.



          Both Redux and Vuex store state in plain objects and require their API to be defined as a functions (each with it's own architecture), that will be merged into a single store instance. This serves purpose of providing reactive updates on state changes, warnings when state is mutated outside of mutations or dispatched action/mutation is not registered. My opinion is that this approach is efficient in absence of type safety, which both libraries are initially meant to be used without.



          For example, in Vuex if you decide to call an action or mutation from another module, you would use dispatch (for actions) or commit (for mutations) with a type referenced as full path to the module:



          dispatch('profile/addPortfolio', payload, root: true )
          commit('profile/ADD_PORTFOLIO', payload, root: true )


          Meaning, that both invocations should be done with store instance methods and are expected to be registered on current store instance, rather than importing and invoking module's action or mutation directly.



          In case Typescript is integrated into the project, it is possible to use class-based structure or decorators for the store and it's modules. Again, classes will be compiled to match store library architecture, but enhances development experience.



          As for Vuex, following libraries are worth checking out for using with Typescript:



          • vue-property-decorator

          • vuex-module-decorators


          • vuex-class - a helper to use vuex decorators inside components

          TLDR
          Such architecture is defined by mentioned libraries for usage without type-safety, while still allowing reactivity and centralized state mutation. Constants help to ensure that actions/mutations are registered on store instance, increase predictability and provide autocomplete for code editors.






          share|improve this answer














          Both Redux and Vuex create a single store instance from declared set of modules, that is responsible for dispatching/committing registered actions/mutations that require type to be provided as a string value. While scaling the application, usage of actions/mutations becomes quite widespread and using plain strings will reduce state mutation predictability significantly.



          Using constants, such as:



          export const ADD_PORTFOLIO = 'ADD_PORTFOLIO'


          allows to list all available state mutations in a separate list-like file, thus providing clear understanding of possible changes, while avoiding typos inside store modules and allowing IDE and code editors to autocomplete or highlight invalid references to constant types. Which reduces debugging time and would not be possible with plain strings. It is not required, neither it is an invention of mentioned libraries. It works well with globally invoked events (e.g. Node EvenEmitter, Electron ipcRenderer, etc) for the same reasons.



          Both Redux and Vuex store state in plain objects and require their API to be defined as a functions (each with it's own architecture), that will be merged into a single store instance. This serves purpose of providing reactive updates on state changes, warnings when state is mutated outside of mutations or dispatched action/mutation is not registered. My opinion is that this approach is efficient in absence of type safety, which both libraries are initially meant to be used without.



          For example, in Vuex if you decide to call an action or mutation from another module, you would use dispatch (for actions) or commit (for mutations) with a type referenced as full path to the module:



          dispatch('profile/addPortfolio', payload, root: true )
          commit('profile/ADD_PORTFOLIO', payload, root: true )


          Meaning, that both invocations should be done with store instance methods and are expected to be registered on current store instance, rather than importing and invoking module's action or mutation directly.



          In case Typescript is integrated into the project, it is possible to use class-based structure or decorators for the store and it's modules. Again, classes will be compiled to match store library architecture, but enhances development experience.



          As for Vuex, following libraries are worth checking out for using with Typescript:



          • vue-property-decorator

          • vuex-module-decorators


          • vuex-class - a helper to use vuex decorators inside components

          TLDR
          Such architecture is defined by mentioned libraries for usage without type-safety, while still allowing reactivity and centralized state mutation. Constants help to ensure that actions/mutations are registered on store instance, increase predictability and provide autocomplete for code editors.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 8 at 18:11

























          answered Nov 8 at 18:05









          aBiscuit

          1,2421513




          1,2421513











          • Hi MrBiscuit, Thanks a lot for the extensive explanation. What i dont yet understand thought is the fact that it must be an object with functions in it and reference to it through the function names as strings. Do you know what the plus side of it it or the reason to design it like this?
            – redlum
            Nov 8 at 20:15






          • 1




            Looking at source code of dispatch methods Redux, Vuex - not only do they validate and dispatch actions, but also notify all subscribers of state changes. Which is a Observer pattern. Also, such approach allows to create namespaces for actions/mutations, while keeping it all on a single store instance.
            – aBiscuit
            Nov 8 at 22:08

















          • Hi MrBiscuit, Thanks a lot for the extensive explanation. What i dont yet understand thought is the fact that it must be an object with functions in it and reference to it through the function names as strings. Do you know what the plus side of it it or the reason to design it like this?
            – redlum
            Nov 8 at 20:15






          • 1




            Looking at source code of dispatch methods Redux, Vuex - not only do they validate and dispatch actions, but also notify all subscribers of state changes. Which is a Observer pattern. Also, such approach allows to create namespaces for actions/mutations, while keeping it all on a single store instance.
            – aBiscuit
            Nov 8 at 22:08
















          Hi MrBiscuit, Thanks a lot for the extensive explanation. What i dont yet understand thought is the fact that it must be an object with functions in it and reference to it through the function names as strings. Do you know what the plus side of it it or the reason to design it like this?
          – redlum
          Nov 8 at 20:15




          Hi MrBiscuit, Thanks a lot for the extensive explanation. What i dont yet understand thought is the fact that it must be an object with functions in it and reference to it through the function names as strings. Do you know what the plus side of it it or the reason to design it like this?
          – redlum
          Nov 8 at 20:15




          1




          1




          Looking at source code of dispatch methods Redux, Vuex - not only do they validate and dispatch actions, but also notify all subscribers of state changes. Which is a Observer pattern. Also, such approach allows to create namespaces for actions/mutations, while keeping it all on a single store instance.
          – aBiscuit
          Nov 8 at 22:08





          Looking at source code of dispatch methods Redux, Vuex - not only do they validate and dispatch actions, but also notify all subscribers of state changes. Which is a Observer pattern. Also, such approach allows to create namespaces for actions/mutations, while keeping it all on a single store instance.
          – aBiscuit
          Nov 8 at 22:08


















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53212227%2fwhy-doesnt-flux-state-management-use-static-functions-instead-of-named-proper%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

          Edmonton

          Crossroads (UK TV series)