Skip to content

Commit 87f0ada

Browse files
committed
Merge pull request #385 from magento-vanilla/PR
[Vanilla] (MAGETWO-38867) Improved declaration of widgets with `mixins` node Merged with failed (red) L1/REST EE build and failed (red) FAT/CreateGroupedProductEntityTest build. Reffering to those fails are know isssue and also fails in current mainline.
2 parents 140595d + c660f9d commit 87f0ada

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

lib/web/mage/apply/main.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ define([
1313
nodeSelector = '[' + dataAttr + ']';
1414

1515
/**
16-
* Initializes components assigned to a specfied element via data-* attribute.
16+
* Initializes components assigned to a specified element via data-* attribute.
1717
*
1818
* @param {HTMLElement} el - Element to initialize components with.
1919
* @param {Object|String} config - Initial components' config.
2020
* @param {String} component - Components' path.
2121
*/
2222
function init(el, config, component) {
2323
require([component], function (fn) {
24+
2425
if (typeof fn === 'object') {
2526
fn = fn[component];
2627
}
@@ -65,11 +66,29 @@ define([
6566
_.toArray(nodes)
6667
.map(getData)
6768
.concat(virtuals)
68-
.forEach(function (item) {
69-
_.each(item.data, init.bind(null, item.el));
69+
.forEach(function (itemContainer) {
70+
var configStack,
71+
element = itemContainer.el;
72+
73+
_.each(itemContainer.data, function (obj, key) {
74+
if (obj.mixins) {
75+
require(obj.mixins, function () {
76+
for (var i = 0, len = arguments.length; i < len; i++) {
77+
$.extend(true, itemContainer.data[key], arguments[i](itemContainer.data[key], element));
78+
}
79+
80+
delete obj.mixins;
81+
_.each(itemContainer.data, init.bind(null, element));
82+
})
83+
} else {
84+
_.each(itemContainer.data, init.bind(null, element));
85+
}
86+
87+
}
88+
);
89+
7090
});
7191
},
72-
7392
applyFor: init
7493
};
7594
});

lib/web/mage/apply/scripts.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,30 @@ define([
2828
* Merges provided data with a current data
2929
* of a elements' "data-mage-init" attribute.
3030
*
31-
* @param {Object} components - Object with compoenets and theirs configuration.
31+
* @param {Object} components - Object with components and theirs configuration.
3232
* @param {HTMLElement} elem - Element whose data should be modified.
3333
*/
3434
function setData(components, elem) {
3535
var data = elem.getAttribute(dataAttr);
3636

3737
data = !!data ? JSON.parse(data) : {};
38+
_.each(components, function(obj, key) {
39+
if (_.has(obj, 'mixins')) {
40+
data[key].mixins = data[key].mixins || [];
41+
data[key].mixins = data[key].mixins.concat(obj.mixins);
42+
delete obj.mixins;
43+
}
44+
});
45+
3846
data = $.extend(true, data, components);
3947
data = JSON.stringify(data);
40-
4148
elem.setAttribute(dataAttr, data);
4249
}
4350

4451
/**
4552
* Search for the elements by privded selector and extends theirs data.
4653
*
47-
* @param {Object} components - Object with compoenets and theirs configuration.
54+
* @param {Object} components - Object with components and theirs configuration.
4855
* @param {String} selector - Selector for the elements.
4956
*/
5057
function processElems(components, selector) {

0 commit comments

Comments
 (0)