Skip to content

Commit 6023ac7

Browse files
committed
Added raf untility for window resizing
1 parent ea18bd7 commit 6023ac7

File tree

1 file changed

+12
-23
lines changed
  • app/code/Magento/Ui/view/base/web/js/grid

1 file changed

+12
-23
lines changed

app/code/Magento/Ui/view/base/web/js/grid/masonry.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
*/
55
define([
66
'Magento_Ui/js/grid/listing',
7+
'Magento_Ui/js/lib/view/utils/raf',
78
'jquery',
89
'ko',
910
'underscore'
10-
], function (Listing, $, ko, _) {
11+
], function (Listing, raf, $, ko, _) {
1112
'use strict';
1213

1314
return Listing.extend({
@@ -66,7 +67,12 @@ define([
6667
* Applied when container width is greater than max width in the containerWidthToMinRatio matrix.
6768
* @param int
6869
*/
69-
defaultMinRatio: 10
70+
defaultMinRatio: 10,
71+
72+
/**
73+
* Layout update FPS during window resizing
74+
*/
75+
refreshFPS: 60
7076
},
7177

7278
/**
@@ -105,29 +111,12 @@ define([
105111
* Set event listener to track resize event
106112
*/
107113
setEventListener: function () {
108-
var running = false,
109-
handler = function () {
114+
window.addEventListener('resize', function () {
115+
raf(function () {
110116
this.containerWidth = window.innerWidth;
111117
this.setLayoutStyles();
112-
}.bind(this);
113-
114-
window.addEventListener('resize', function () {
115-
if (!running) {
116-
running = true;
117-
118-
if (window.requestAnimationFrame) {
119-
window.requestAnimationFrame(function () {
120-
handler();
121-
running = false;
122-
});
123-
} else {
124-
setTimeout(function () {
125-
handler();
126-
running = false;
127-
}, 66);
128-
}
129-
}
130-
});
118+
}.bind(this), this.refreshFPS);
119+
}.bind(this));
131120
},
132121

133122
/**

0 commit comments

Comments
 (0)