Last active
February 26, 2021 09:17
-
-
Save alecarg/ed0516132e9c8a31c66f13fbccd292cf to your computer and use it in GitHub Desktop.
Magento 2 mixins (extend/override for UIComponents)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Magento 2 mixins for js files that return an UIComponent | |
* (based on https://alanstorm.com/the-curious-case-of-magento-2-mixins/) | |
* (for files that return an object literal: https://gist.github.com/alecarg/71a28b6d0ce2c3b7073481cc52fe1e23) | |
* (for files that return a function: ) | |
*/ | |
define([ | |
], function () { | |
'use strict'; | |
return function(targetModule){ | |
/* | |
* Extend | |
*/ | |
return targetModule.extend({ | |
someMethod: function(){ | |
// do something before | |
var result = this._super(); // call original method (if needed) | |
// do something after | |
return result; | |
} | |
}); | |
/* | |
* Override | |
*/ | |
return targetModule.extend({ | |
someOtherMethod: function(){ | |
/* copy code from someOtherFn here if needed or write your own; also attempt to | |
return in line with what the original fn returned to avoid breaking anything */ | |
} | |
}); | |
return targetModule; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment