'veI have been experimenting with a custom module with KnockoutJs on the frontend in M2.
I've created two components: a ProductPackage and a ProductPackagePopop. FunctionalyFunctionally, the ProductPackage triggers a modal whichthat renders some details about the package's children.
These two components share quite somethe same logic which iI would like to share between the components. For example:, both have a function 'initTranslations'initTranslation
which retrieves the right translations for this store id.
Since i'mI am new to the magento2 Knockout implementation, is there some way to create a base component from which my two components inherit the shared logic? Or a trait like in PHP. I've looked at mixins, but it seems to me it's more fit to extend external is.
define(['uiComponent'], function (Component) {
return Component.extend({
store_id: 0,
initialize: function (config) {
this.store_id = config.store_id;
this.initTranslations(config.productPackage);
},
initTranslations: function (productPackage) {
//some logic here
},
children: function(){
// retrieves children
}
});
});
});
I've found this: https://stackoverflow.com/questions/16569810/knockout-viewmodel-base-class-javascript-inheritance , but iI find it hard to fit that in the M2 Knockout/RequireJs wrapper.