mirror of
https://github.com/wu736139669/ASHEBShop-h5.git
synced 2026-10-07 19:26:23 +00:00
32 lines
1.0 KiB
JavaScript
32 lines
1.0 KiB
JavaScript
import _Object$keys from 'babel-runtime/core-js/object/keys';
|
|
/**
|
|
* Helper utility that updates the specified callback whenever any of the specified indices have changed.
|
|
*/
|
|
export default function createCallbackMemoizer() {
|
|
var requireAllKeys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
|
|
var cachedIndices = {};
|
|
|
|
return function (_ref) {
|
|
var callback = _ref.callback,
|
|
indices = _ref.indices;
|
|
|
|
var keys = _Object$keys(indices);
|
|
var allInitialized = !requireAllKeys || keys.every(function (key) {
|
|
var value = indices[key];
|
|
return Array.isArray(value) ? value.length > 0 : value >= 0;
|
|
});
|
|
var indexChanged = keys.length !== _Object$keys(cachedIndices).length || keys.some(function (key) {
|
|
var cachedValue = cachedIndices[key];
|
|
var value = indices[key];
|
|
|
|
return Array.isArray(value) ? cachedValue.join(',') !== value.join(',') : cachedValue !== value;
|
|
});
|
|
|
|
cachedIndices = indices;
|
|
|
|
if (allInitialized && indexChanged) {
|
|
callback(indices);
|
|
}
|
|
};
|
|
} |