Hello Magento Friends,
We are back with “How-To” Magento Tutorials. Today’s topic is Magento 2: How Knockout-es5 Library Work.
Knockout-es5 is a plugin by Steve Sanderson to simplify the syntax. The knockout-es5 plugin adds support for ECMAScript 5 properties. With knockout-es5 you can use simpler syntax with your code and bindings. Knockout-ES5 works in ECMAScript 5-capable browsers.
Magento 2 provides a knockout js library to make our variable observable. Along with that one advanced functionality is given like knockout-es5, using it we can make all variables observable in bulk using the tracking method.
Observable is helpful to fulfill MVVM (Model-View-View-Model) architecture.
Let us take an example,
ko.observable(varMyName)
Further, to access the value, it is necessary to call it like a function: varMyName()
UiElement = requirejs('uiElement'); //define a new constructor function based on uiElement OurClass = UiElement.extend({ defaults:{ tracks:{ varMyName: true, varTempMyName: true } } }); //create a new object ourViewModel = new OurClass; //set a default value ourViewModel.varMyName = 'a default value'; //setup a callback ourViewModel.on('varMyName', function(value){ console.log("Another callback: " + value); }); //set the value (notice the normal javascript assignment) //and you should see the "Another callback" output ourViewModel. varMyName = 'a new value';
So here varMyName automatically works like observable
Hence, this was all about How Knockout-es5 Library Work in Magento 2. For any queries or help feel comfortable reaching me via the comment part. Do not forget to share the article. Stay informed!
Happy Coding
Hello Magento Friends, In today’s blog, I will explain How to Add Tooltip in Checkout…
MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…
In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…
Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…
The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…
Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…