One of the main features of any modern JavaScript framework is reactivity. in this article you're gonna understand how Vue.Js tackles this by :
Understanding the problem.
Vue's solution to that problem.
The Problem
You're coding using vanilla JavaScript and the code calculates the total price of some products and logs it...
Now our price has gone up to 20 per product, let's log the price again....
to our surprise it's still 10 but why?! that's supposed to be 40, right? WRONG.
Take a good look at the code again, the calculation only happens once. We never told JavaScript to track any changes nor we told it that the total price calculation is meant to update according to changes, and here's where The Reactive Vue really shines...
Vue's solution
The approach is that we want to be able to store the critical value in some sort and be able to track it and trigger the effect when the value changes.
The calculation is wrapped in a function called "effect" and stored for later use when our value(price) changes. For that to happen, there are 3 main operations(functions) to run:
track() -> to actually save our code
effect() -> the actual behavior/calculation
Brainstorming...
Can there be multiple effects? How does Vue handle that?
What happens when we want to track multiple properties?
What if we track objects...?
I'll answer all that in the upcoming post as well as your questions. Feel free to ask me about anything, it's ok we're all learning here.
Leave a β₯οΈ for the post if it was useful to reach more devs π§βπ»π§βπ»...
Follow me for more related content...
recourses:
https://www.youtube.com/c/VueMastery
Top comments (1)
Great Job Bro