Skip to content

Commit f57b7f8

Browse files
author
Denys Rul
committed
MAGETWO-33502: Inline JS code elimination (Priority 1 scripts)
- Fix maximum line length error - Remove unnecessary functions
1 parent 1d02b92 commit f57b7f8

File tree

3 files changed

+12
-34
lines changed

3 files changed

+12
-34
lines changed

app/code/Magento/Ui/view/base/templates/form/default.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
/**
77
* @var \Magento\Ui\Component\Form $block
88
*/
9+
$formConfig = $block->getRenderContext()->getConfigBuilder()->toJsonNew($block->getRenderContext()->getStorage());
910
?>
1011
<script type="text/x-magento-init">
1112
{
1213
"*": {
13-
"Magento_Ui/js/core/app": <?php echo $block->getRenderContext()->getConfigBuilder()->toJsonNew($block->getRenderContext()->getStorage()); ?>
14+
"Magento_Ui/js/core/app": <?php echo $formConfig; ?>
1415
}
1516
}
1617
</script>

lib/web/mage/apply/main.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,6 @@ define([
3333
});
3434
}
3535

36-
/**
37-
* Searches for elements with a 'data-mage-init' attribute.
38-
*
39-
* @returns {Array} An array of elements with 'data-mage-init' attribute.
40-
*/
41-
function getElems() {
42-
var elems;
43-
44-
elems = document.querySelectorAll(nodeSelector);
45-
46-
return _.toArray(elems);
47-
}
48-
4936
/**
5037
* Parses elements 'data-mage-init' attribute as a valid JSON data.
5138
* Note: data-mage-init attribute will be removed.
@@ -72,11 +59,12 @@ define([
7259
* data-mage-init='{"path/to/component": {"foo": "bar"}}'
7360
*/
7461
apply: function () {
75-
var virtual = processScripts();
62+
var virtuals = processScripts(),
63+
nodes = document.querySelectorAll(nodeSelector);
7664

77-
getElems()
65+
_.toArray(nodes)
7866
.map(getData)
79-
.concat(virtual)
67+
.concat(virtuals)
8068
.forEach(function (item) {
8169
_.each(item.data, init.bind(null, item.el));
8270
});

lib/web/mage/apply/scripts.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ define([
1010

1111
var scriptSelector = 'script[type="text/x-magento-init"]',
1212
dataAttr = 'data-mage-init',
13-
virtual = [];
13+
virtuals = [];
1414

1515
/**
1616
* Adds components to the virtula list.
1717
*
1818
* @param {Object} components
1919
*/
2020
function addVirtual(components) {
21-
virtual.push({
21+
virtuals.push({
2222
el: false,
2323
data: components
2424
});
@@ -63,19 +63,6 @@ define([
6363
_.toArray(elems).forEach(iterator);
6464
}
6565

66-
/**
67-
* Searches for script tags whith a 'text/x-magento-init' type.
68-
*
69-
* @returns {Array} An array of elements script nodes.
70-
*/
71-
function getNodes() {
72-
var elems;
73-
74-
elems = document.querySelectorAll(scriptSelector);
75-
76-
return _.toArray(elems);
77-
}
78-
7966
/**
8067
* Parses content of a provided script node.
8168
* Note: node will be removed from DOM.
@@ -115,12 +102,14 @@ define([
115102
* }
116103
*/
117104
return function () {
118-
getNodes()
105+
var nodes = document.querySelectorAll(scriptSelector);
106+
107+
_.toArray(nodes)
119108
.map(getNodeData)
120109
.forEach(function (item) {
121110
_.each(item, processElems);
122111
});
123112

124-
return virtual.splice(0, virtual.length);
113+
return virtuals.splice(0, virtuals.length);
125114
};
126115
});

0 commit comments

Comments
 (0)