@@ -13,14 +13,15 @@ define([
13
13
nodeSelector = '[' + dataAttr + ']' ;
14
14
15
15
/**
16
- * Initializes components assigned to a specfied element via data-* attribute.
16
+ * Initializes components assigned to a specified element via data-* attribute.
17
17
*
18
18
* @param {HTMLElement } el - Element to initialize components with.
19
19
* @param {Object|String } config - Initial components' config.
20
20
* @param {String } component - Components' path.
21
21
*/
22
22
function init ( el , config , component ) {
23
23
require ( [ component ] , function ( fn ) {
24
+
24
25
if ( typeof fn === 'object' ) {
25
26
fn = fn [ component ] ;
26
27
}
@@ -32,31 +33,7 @@ define([
32
33
}
33
34
} ) ;
34
35
}
35
- /**
36
- * Initializes mixins assigned to a specfied component.
37
- *
38
- * @param {Object } mixinList - object contains mixins list.
39
- * @param {Object } itemContainer - object with component config and DOM element link.
40
- * @return {Promise }
41
- */
42
- function initMixins ( mixinList , itemContainer ) {
43
- var configStack ,
44
- element = itemContainer . el ,
45
- result = $ . Deferred ( ) ;
46
-
47
- _ . each ( mixinList , function ( mixinArray , componentName ) {
48
- configStack = itemContainer . data [ componentName ] ;
49
- require ( mixinArray , function ( ) {
50
- for ( var i = 0 , len = arguments . length ; i < len ; i ++ ) {
51
- $ . extend ( true , configStack , arguments [ i ] ( configStack , element ) ) ;
52
- }
53
-
54
- result . resolve ( itemContainer ) ;
55
- } ) ;
56
- } ) ;
57
36
58
- return result ;
59
- }
60
37
/**
61
38
* Parses elements 'data-mage-init' attribute as a valid JSON data.
62
39
* Note: data-mage-init attribute will be removed.
@@ -90,21 +67,27 @@ define([
90
67
. map ( getData )
91
68
. concat ( virtuals )
92
69
. forEach ( function ( itemContainer ) {
93
- var mixins = itemContainer . data . mixins ;
94
- delete itemContainer . data . mixins ;
70
+ var configStack ,
71
+ element = itemContainer . el ;
72
+
73
+ _ . each ( itemContainer . data , function ( obj , key ) {
74
+
75
+ if ( obj . mixins ) {
76
+ require ( obj . mixins , function ( ) {
77
+ for ( var i = 0 , len = arguments . length ; i < len ; i ++ ) {
78
+ $ . extend ( true , itemContainer . data [ key ] , arguments [ i ] ( itemContainer . data [ key ] , element ) ) ;
79
+ }
80
+
81
+ delete obj . mixins ;
82
+ _ . each ( itemContainer . data , init . bind ( null , element ) ) ;
83
+ } )
84
+ } else {
85
+ _ . each ( itemContainer . data , init . bind ( null , element ) ) ;
86
+ }
87
+
88
+ }
89
+ ) ;
95
90
96
- if ( mixins ) {
97
- $ . when (
98
- initMixins ( mixins , itemContainer )
99
- ) . then ( function ( mergedItemContainer ) {
100
- _ . each (
101
- mergedItemContainer . data ,
102
- init . bind ( null , mergedItemContainer . el )
103
- )
104
- } ) ;
105
- } else {
106
- _ . each ( itemContainer . data , init . bind ( null , itemContainer . el ) ) ;
107
- }
108
91
} ) ;
109
92
} ,
110
93
applyFor : init
0 commit comments