Skip to content

Commit 8794f4e

Browse files
portchrisunicoder88
authored andcommitted
Better define an Require JS alias and preference
- Take notes from Magento devdocs to better explain Require JS alias, previous was more of a preference. - Take notes from Magento devdocs to better explain Require JS preference, previous was more of an alias.
1 parent 1ecc894 commit 8794f4e

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

3. Customizing the Magento UI/4. Utilize JavaScript in Magento.md

+13-10
Original file line numberDiff line numberDiff line change
@@ -224,24 +224,27 @@ it’s easier and more effective to use a UI component.
224224
We are interested in:
225225
- map as alias - same as defining virtual type preference in DI
226226
```js
227-
var config = {
228-
map: {
229-
'*': {
230-
'Magento_Swatches/js/swatch-renderer' : 'Custom_Module/js/swatch-renderer'
231-
}
227+
map: {
228+
'*': {
229+
alias: 'Vendor_Module/js/complex/path/amd-module'
232230
}
233-
};
231+
}
234232
```
233+
Now we can use our 'Vendor_Module/js/complex/path/module' using `alias` in any RequireJS module or config file without needing to type the entire path. For example, in Magento, `catalogAddToCart` is mapped to 'Magento_Catalog/js/catalog-add-to-cart' and can be used anywhere as a RequireJS module name.
234+
235235
- map as preference - same as preference in DI, replace one class with another
236236
```js
237237
var config = {
238-
map: {
239-
'*': {
240-
uiElement: 'Magento_Ui/js/lib/core/element/element',
241-
}
238+
"map": {
239+
"*": {
240+
"<default_component>": "<custom_component>"
242241
}
242+
}
243243
};
244244
```
245+
* <default_component>: the name of the default component you replace
246+
* <custom_component>: the name of the custom component
247+
245248
- mixins - same as around plugins in DI. This is Magento customization over requireJS
246249
```js
247250
var config = {

0 commit comments

Comments
 (0)