I found the following code in Magento 2 HTML:
<div id="cart-totals" class="cart-totals" data-bind="scope:'block-totals'">
Magento 2 uses Knockout on frontend but I cannot found in Knockout docs what does keyword "scope" mean in this context. Is it a Magento 2 feature?
Your assumption is right, the scope binding is not build-in into knockout, but a magento feature.
From what I understood, magento uses the applyBindings function from knockout without assigning a viewmodel. The scope binding then looks for and loads a registered viewmodel (in this case: 'block-totals') and applies this to the DOM node, where you have your scope binding.
For detailed information, have a look here (and give the guy some credit, too :))
https://magento.stackexchange.com/questions/120447/how-does-magento-2-apply-knockoutjs-bindings
http://alanstorm.com/magento_2_knockoutjs_integration/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With