Gaurav Panchal

Vue.js Transformation Documentation

Overview

This document explains the transformation of the Evolution Framework application from vanilla JavaScript to Vue.js 3 using CDN.

Key Changes Made

1. HTML Structure Transformation

Before (Vanilla JS)

After (Vue.js)

Example Transformation:

<!-- Before: Vanilla JS -->
<button class="nav-btn active" data-view="dashboard">Dashboard</button>

<!-- After: Vue.js -->
<button 
    v-for="view in navigationViews" 
    :key="view.key"
    class="nav-btn" 
    :class="{ active: activeView === view.key }"
    @click="setActiveView(view.key)">
    
</button>

2. State Management

Before (Vanilla JS)

// Global variables
let assessmentScores = { swadharma: 0, operating: 0, ... };
let currentAssessment = { pillar: 'swadharma', ... };

After (Vue.js)

data() {
  return {
    assessmentScores: { swadharma: 0, operating: 0, ... },
    currentAssessment: { pillar: 'swadharma', ... },
    // All state centralized in Vue component
  }
}

3. Event Handling

Before (Vanilla JS)

// Manual event listener attachment
nextButton.addEventListener('click', handleNextQuestion);
pillarSelectButtons.forEach(button => {
  button.addEventListener('click', () => {
    const pillar = button.dataset.assess;
    selectPillarForAssessment(pillar);
  });
});

After (Vue.js)

<!-- Declarative event handling -->
<button @click="handleNextQuestion">Next</button>
<button 
    v-for="(pillar, key) in pillarMappings" 
    @click="selectPillarForAssessment(key)">
    
</button>

4. Dynamic Content Rendering

Before (Vanilla JS)

// Manual DOM manipulation
function updateDashboardScores() {
  Object.entries(assessmentScores).forEach(([pillarKey, score]) => {
    const pillarElement = document.querySelector(`[data-pillar="${pillarKey}"] .pillar-score`);
    if (pillarElement) {
      pillarElement.textContent = `${score}%`;
      pillarElement.className = 'pillar-score';
      if (score >= 61) pillarElement.classList.add('high');
    }
  });
}

After (Vue.js)

<!-- Reactive rendering -->
<div class="pillar-score" :class="getScoreColorClass(assessmentScores.swadharma)">
  %
</div>

5. Component Structure

Before (Vanilla JS)

After (Vue.js)

Key Vue.js Features Utilized

1. Reactive Data Binding

// Automatic UI updates when data changes
assessmentScores: {
  swadharma: 0,
  operating: 0,
  // ... other pillars
}

2. Computed Properties

computed: {
  currentPillarData() {
    return this.pillarMappings[this.currentAssessment.pillar];
  },
  overallProgress() {
    const scores = Object.values(this.assessmentScores);
    return Math.round(scores.reduce((sum, score) => sum + score, 0) / scores.length);
  }
}

3. Template Directives

4. Lifecycle Hooks

mounted() {
  this.loadAssessmentData();
  if (this.activeView === 'progress') {
    this.$nextTick(() => {
      this.updateRadarChart();
    });
  }
}

Benefits of Vue.js Transformation

1. Improved Developer Experience

2. Reduced Boilerplate Code

3. Better Performance

4. Enhanced Maintainability

File Structure

evolution/
├── index.html          # Original vanilla JS version
├── app.js             # Original vanilla JS logic
├── vue-index.html     # New Vue.js HTML template
├── vue-app.js         # New Vue.js application logic
└── style.css          # Shared CSS (unchanged)

Key Differences in Implementation

Assessment Flow

Vanilla JS:

  1. Manual form state management
  2. DOM queries for form elements
  3. Manual validation and progression

Vue.js:

  1. Reactive form state with v-model
  2. Computed properties for validation
  3. Method calls for progression

Vanilla JS:

function showPillarModal(pillarKey) {
  const modal = document.getElementById('pillar-modal');
  modal.classList.remove('hidden');
  // Manual content updates
}

Vue.js:

showPillarModal(pillarKey) {
  this.modal = {
    show: true,
    pillar: this.pillarMappings[pillarKey],
    // Reactive updates
  };
}

Integration Matrix

Vanilla JS:

Vue.js:

Migration Path

To migrate existing applications to Vue.js:

  1. Setup Vue.js CDN: Add Vue.js script tag
  2. Wrap in Vue App: Create Vue application instance
  3. Move State to Data: Transfer global variables to data()
  4. Convert Event Listeners: Replace with Vue event directives
  5. Use Template Syntax: Replace DOM manipulation with reactive templates
  6. Add Computed Properties: For derived state calculations
  7. Lifecycle Hooks: Replace initialization functions

Performance Considerations

Bundle Size

Runtime Performance

Conclusion

The Vue.js transformation provides:

The reactive nature of Vue.js eliminates much of the manual DOM manipulation required in vanilla JavaScript, while providing a more structured and predictable development experience.