Magento 2 Checkout_module JS structure

188 Views Asked by At

I have been learning magento since past 2 months but i have been stuck at a point in learning .

What i can't understand is Why there are 3 folders in JS of checkout_module VIEW,ACTION,MODEL are they for any reason or they just created it to keep file separate for better knowledge and understanding

1

There are 1 best solutions below

0
Cyril_Leblanc On

Magento2 source code (at least for the javascript part) separate folders depending on the use case. I'm assuming you talk about the Magento_Checkout module

Since Magento2 use KnockoutJs there is a view folder to contain view model of these components (there surely all have a .html in the template folder with the same path or so).

The action folder contain functions to call to perform "action" like making an order or adding an item to cart.

The model is often use to interact with the local storage or data object.

I don't think there's a convention on how to store your javascript files other than storing them in Vendor_Module/view/frontend/web/js folder. I think it's better to organize your code like the code source.

Also I'm still learning so my answer may not be totally complete.