Vue Versus React:
Overview of Frameworks
· Reactive or computed properties from Knockout and Ember.
· One-way data flow and virtual DOM (Document Object Model) from React
· HTML style template that are directive heavy from Angular
The topic of “Vue vs React” is very subjective among developers hence biases are determined can by the following:
Templates — JSX or HTML
· JSX have a lot of support of tooling which is in some areas more progressive than Vue’s tooling support for templates. E.g. Type checking, linting and editor autocompletion
The nice thing about Vue is the fact the it also has render funtions and provides support for JSX due to the fact the under certain situation you will require the power of JSX. Vue provides templates by default as less complicated option. Any HTML structure is accepted and results in a few advantages:
· Preprocessors like Pug can be utilised
· Most inexperienced developers will feel a lot more familiar with working with HTML, hence the template feels easier to read and write.
· There is less of a learning curve which results in designers and inexperienced developers being able to add to the codebase
· The process of migration for existing web applications to take advantage of Vue’s reactivity is a lot simpler due to Vue having HTML based templates.
Achieving more with directives
An argument could be made saying the one must know a Domain Specific Language (DSL) to construct template, however, I can personally say that DSL is easy to understand. Vue takes the directive style syntax from Angular and can help developers get a lot done with a reduced amount of code. One example would be the use of modifiers link v-on. More code would be required to perform the same task
Vue and React both have remarkably speed, both being very close speed is would not be a deciding factor under this category. For details view the link following link, which examines update/render performance with basic component trees. Hence In terms of performance for these two frameworks, let us turn our attention to performance optimization
When the state of a component is changed in React, this condition makes the entire component sub-tree re-render at the root of the component. Re-renders of child components that are not necessary can be sidestepped with the utilization of shouldComponentUpdate and Pure Component. To put it in simple terms shouldComponentUpdate and Pure Component are essentially used to make sure that when you get new data in some way, that it’s worth updating your tree. It is possible to utilize structures of data that are unchanging over time to ensure that modifications of your state are optimized. shouldComponentUpdate and Pure Component make the assumption that the render of the sub-tree is determined by the present component’s props. However, should this not be the case, then optimizations could result inconsistent state
With VueJS’s reactivity model, all data (props, state etc.) are observable by default, hence the system is aware of which components need re-rendering during a state change. So, in other words, every component has shouldComponentUpdate applied by default. Therefore, this removes the requirement for performance optimization classes, minimizing the developer’s work load, allowing him/her to spend more time on developing the web application as it grows.
Lifecycles and the Reactivity Model
The reactivity model and lifecycles play a big role in performance optimization efforts. VueJS and React have extremely similar lifecycles. The following table shows the life-cycles of Vue and its equivalents in React
The notable life cycles in React which do not have equivalents in VueJS are the following:
These lifecycle hooks practically ensure that used to make sure that when you get new data in some way, that it’s worth updating your tree as mentioned before. One would think that since Vue doesn’t have these missing lifecycle hooks that you can’t write high performance Vue, however, the secret lies within Vue’s reactivity model as mentioned briefly before. Let us take a look at some example comparing Vue’s reactivity to React’s reactivity to get a more detailed understanding:
VueJS Reactivity Model
Figure 1: Code snippet portraying Vue Reactivity
· Vue’s reactivity model is very similar to Ember.js. All Vue data(props, state) are observable by default
· Vue automatically tracks reactive dependencies of functions.
· Hence, in Figure 1, firstName is just being rendered. Figure 1 has more data that it could render i.e lastName, but since Vue is tracking the render call, when it rendered the first time, Vue takes note that it only uses firstName so down the line, if lastName gets updated, Vue will not even bother asking about re-rendering again since it know that its impossible for render to be using lastName. Hence the above render() will one be called when firstName is updated.
Figure 2: Code snippet portraying React Reactivity
During a state change, you can intercept updates to your states and props and make a judgement call on whether or not, you can re-render. The issue is as your render function grows, you have to grow shoudlComponentUpdate() as well to keep it at high performance.
Vuex vs Redux in large scale applications
For web applications on a big scale, both VueJS and React provide strong solutions. For state management, the community of React developed Redux which can implemented into any React or even Vue application with minimal difficulty. VueJS used this model and enhanced it creating Vuex which is deeply integrated into the heart of Vue. I believe Vuex provides a greater development experience because Vuex performs mutations on the state instead making it immutable and substituting the entire thing like Redux does with reducer functions. For this reason, when there is a state change, VueJS know which directives are required to be re-rendered.