How Reactivity works in Vue.js

How Reactivity works in Vue.js

Understanding Reactivity in Vue.js Introduction In the realm of Front-end development, “Reactivity” is a fundamental concept widely utilized, yet often not fully comprehended. In the context of Front-end frameworks, reactivity in Vue.js refers to the automatic reflection of changes in the application state onto the Document Object Model (DOM). Reactivity in Vue.js Reactivity is an […]

Scope
  • Website Optimization
  • Conversion Boost
  • Performance
Use Case
  • Conversion
  • Engagement
  • CRO Audit
Industry
  • E-commerce
  • Fashion Retail
  • Shopify Platform
Tools Used
  • Google PageSpeed
  • Insights
  • Lighthouse
  • Google Tag Manager

The Challenge

Understanding Reactivity in Vue.js Introduction In the realm of Front-end development, "Reactivity" is a fundamental concept widely utilized, yet often not fully comprehended. In the context of Front-end frameworks, reactivity in Vue.js refers to the automatic reflection of changes in the application state onto the Document Object Model (DOM). Reactivity in Vue.js Reactivity is an integral part of Vue.js, seamlessly integrated into the framework. To illustrate, consider a simple example of reactivity using two-way binding (via v-model): javascript new Vue({ el: '#app', data: { message: '' } }) In this Vue.js example, any alteration in the data model layer is instantly mirrored in the view layer: html <!-- Vue.js Template --> <input type="text" v-model="message"> {{ message }} A Vanilla JavaScript Comparison For those familiar with Vue.js, this reactivity behavior is expected. However, when attempting to replicate this in vanilla JavaScript, disparities become evident. In the absence of Vue.js, standard JavaScript fails to exhibit the same reactivity. Consider the following example mimicking the Vue.js reactivity example in vanilla JS. Vue.js Reactivity System To comprehend this discrepancy, let's delve into the underlying reactivity system of Vue.js. First Render During the initial rendering, when a data property is accessed (referred to as "touched"), its corresponding getter function is invoked. Watcher Subsequently, a watcher is triggered, responsible for adding the data property as a dependency and invoking the component render function. Component Render Function Vue's component render function, though not simplistic in reality, essentially returns the Virtual DOM Tree with updated data properties, subsequently displayed in the view. Changes in Data The core of Vue.js reactivity lies in handling changes to data properties. When a change occurs in a data property marked as a dependency, its setter function is invoked, notifying the watcher. The watcher, in turn, invokes the component render function, updating the view with the modified data property. Recreating Vue.js Reactivity in Vanilla JavaScript Now, let's embark on recreating Vue.js reactivity in vanilla JavaScript. To comprehend this process thoroughly, we'll break it down into building blocks. Building Blocks of Recreated Reactivity System 1. Data Model Begin by establishing a data model, mirroring the structure of the Vue.js example: javascript let data = { message: '' } 2. Target Function Introduce a global variable 'target' to record target functions associated with data properties: javascript let target = null; 3. Dependency Class Create a Dependency class to manage the storage of target functions for each data property: javascript class Dep { constructor() { this.subscribers = []; } depend() { if (target && !this.subscribers.includes(target)) { this.subscribers.push(target); } } notify() { this.subscribers.forEach((sub) => sub()); } } 4. Tracking Changes Utilize getters and setters, along with Object.defineProperty(), to track changes in data properties and trigger the corresponding target functions: javascript Object.keys(data).forEach((key) => { let internalValue = data[key]; const dep = new Dep();Object.defineProperty(data, key, { get() { dep.depend(); return internalValue; }, set(newVal) { internalValue = newVal; dep.notify(); } }); }); 5. Watchers Introduce a watcher function to encapsulate code that needs to run when a data property's value changes: javascript let watcher = function (func) { target = func; target(); target = null; }; Conclusion By assembling these building blocks, we have successfully recreated the Vue.js reactivity system in vanilla JavaScript. This comprehensive approach provides a deep understanding of reactivity and its implementation in both Vue.js and vanilla JavaScript.

The opportunity

Jockey.in faced significant operational inefficiencies due to a cumbersome custom e-commerce system. The existing setup made it difficult to implement new features quickly and maintain a smooth user experience. Key challenges included

  • Legacy System Limitations: The old custom platform was inflexible, slowing down updates and improvements.
  • Complex Integrations: Connecting CRMs, ERPs, payment systems, and loyalty programs created technical roadblocks
  • Data Migration Complexity: Handling vast product catalogs and historical order data required meticulous planning and security.
  • User Experience Overhaul: Balancing aesthetics, performance, and usability across devices was essential.

Jockey partnered with Foreignerds Inc. to migrate to Shopify Plus, aiming to enhance performance, scalability, and customer satisfaction.

What we did

We created a strategic roadmap to revamp Jockey.in with a focus on performance, scalability, and user experience.

  • Strategic Planning: Analyzed business goals and user pain points to design an effective execution plan.
  • Design Excellence: Delivered responsive, user-centric designs optimized for all devices.
  • Seamless Integration: Connected CRM, ERP, payment, loyalty, and logistics systems within Shopify Plus
  • Data Management Securely migrated extensive product and order data with full accuracy.
  • Custom Features: Implemented omni-channel order routing (ClickPost APIs), OTP login (Gupshup APIs), employee discounts (HR Mantra), gift cards & vouchers (Magicpin, Qwikcilver), and a bra size calculator with ROAS-based product display.
  • Quality & Support: Ensured flawless performance through rigorous testing, continuous monitoring, and post-launch optimization.

The outcome

The migration to Shopify Plus resulted in transformational improvements across all key metrics:

  • 85% Reduction in Operational Costs — demonstrating Shopify Plus’s cost efficiency
  • 50% Improvement in Website Performance — faster operations and enhanced customer experience.
  • 55% Increase in Business Volume — post-migration growth fueled by better UX and streamlined operations
  • 2× Faster Implementation — new features and products could be added twice as quickly

Jockey.in successfully evolved into a high-performance, scalable, and customer-centric e-commerce platform.

The Results

85%

Cost Reduction

50%

Performance Boost

55%

Business Growth

Related Projects

Explore more of our recent work that showcases creativity, precision, and results across different industries.

Advanced Fraud Detection System 6
Advanced Fraud Detection System 6

Challenge: Major bank experiencing high fraud rates needed real-time detection system to prevent financial losses while maintaining seamless user experience.

Advanced Fraud Detection System 5
Advanced Fraud Detection System 5

Challenge: Major bank experiencing high fraud rates needed real-time detection system to prevent financial losses while maintaining seamless user experience.

Edit with