Skip to content

Commit

Permalink
Clear packer rect store after each layout + simplify styles caching s…
Browse files Browse the repository at this point in the history
…ystem.
  • Loading branch information
niklasramo committed Jul 9, 2021
1 parent 4e44c27 commit 042fb75
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 64 deletions.
23 changes: 2 additions & 21 deletions dist/muuri.js
Original file line number Diff line number Diff line change
Expand Up @@ -1220,19 +1220,7 @@
return typeof val === functionType;
}

var isWeakMapSupported = typeof WeakMap === 'function';
var cache$1 = isWeakMapSupported ? new WeakMap() : null;
var cacheInterval = 3000;
var cacheTimer;
var canClearCache = true;
var clearCache = function () {
if (canClearCache) {
cacheTimer = window.clearInterval(cacheTimer);
cache$1 = isWeakMapSupported ? new WeakMap() : null;
} else {
canClearCache = true;
}
};
var cache$1 = typeof WeakMap === 'function' ? new WeakMap() : null;

/**
* Returns the computed value of an element's style property as a string.
Expand All @@ -1249,14 +1237,6 @@
if (cache$1) cache$1.set(element, styles);
}

if (cache$1) {
if (!cacheTimer) {
cacheTimer = window.setInterval(clearCache, cacheInterval);
} else {
canClearCache = false;
}
}

return styles.getPropertyValue(style);
}

Expand Down Expand Up @@ -6474,6 +6454,7 @@
this.slotSizes.length = 0;
this.currentRects.length = 0;
this.nextRects.length = 0;
this.rectStore.length = 0;
this.rectId = 0;
this.slotIndex = -1;

Expand Down
2 changes: 1 addition & 1 deletion dist/muuri.min.js

Large diffs are not rendered by default.

23 changes: 2 additions & 21 deletions dist/muuri.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -1214,19 +1214,7 @@ function isFunction(val) {
return typeof val === functionType;
}

var isWeakMapSupported = typeof WeakMap === 'function';
var cache$1 = isWeakMapSupported ? new WeakMap() : null;
var cacheInterval = 3000;
var cacheTimer;
var canClearCache = true;
var clearCache = function () {
if (canClearCache) {
cacheTimer = window.clearInterval(cacheTimer);
cache$1 = isWeakMapSupported ? new WeakMap() : null;
} else {
canClearCache = true;
}
};
var cache$1 = typeof WeakMap === 'function' ? new WeakMap() : null;

/**
* Returns the computed value of an element's style property as a string.
Expand All @@ -1243,14 +1231,6 @@ function getStyle(element, style) {
if (cache$1) cache$1.set(element, styles);
}

if (cache$1) {
if (!cacheTimer) {
cacheTimer = window.setInterval(clearCache, cacheInterval);
} else {
canClearCache = false;
}
}

return styles.getPropertyValue(style);
}

Expand Down Expand Up @@ -6468,6 +6448,7 @@ function createPackerProcessor(isWorker) {
this.slotSizes.length = 0;
this.currentRects.length = 0;
this.nextRects.length = 0;
this.rectStore.length = 0;
this.rectId = 0;
this.slotIndex = -1;

Expand Down
1 change: 1 addition & 0 deletions src/Packer/PackerProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function createPackerProcessor(isWorker) {
this.slotSizes.length = 0;
this.currentRects.length = 0;
this.nextRects.length = 0;
this.rectStore.length = 0;
this.rectId = 0;
this.slotIndex = -1;

Expand Down
23 changes: 2 additions & 21 deletions src/utils/getStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,8 @@
* Released under the MIT license
* https://github.com/haltu/muuri/blob/master/LICENSE.md
*/
var isWeakMapSupported = typeof WeakMap === 'function';
var cache = isWeakMapSupported ? new WeakMap() : null;
var cacheInterval = 3000;
var cacheTimer;
var canClearCache = true;
var clearCache = function () {
if (canClearCache) {
cacheTimer = window.clearInterval(cacheTimer);
cache = isWeakMapSupported ? new WeakMap() : null;
} else {
canClearCache = true;
}
};

var cache = typeof WeakMap === 'function' ? new WeakMap() : null;

/**
* Returns the computed value of an element's style property as a string.
Expand All @@ -32,13 +21,5 @@ export default function getStyle(element, style) {
if (cache) cache.set(element, styles);
}

if (cache) {
if (!cacheTimer) {
cacheTimer = window.setInterval(clearCache, cacheInterval);
} else {
canClearCache = false;
}
}

return styles.getPropertyValue(style);
}

0 comments on commit 042fb75

Please sign in to comment.