b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / lib / web / mage / requirejs /
Filename/home/dev2.destoffenstraat.com/lib/web/mage/requirejs/resolver.js
Size3.56 kb
Permissionrw-r--r--
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified28-Jan-2025 06:45
Last accessed23-Aug-2025 07:50
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
define([
'underscore',
'domReady!'
], function (_) {
'use strict';

var context = require.s.contexts._,
execCb = context.execCb,
registry = context.registry,
callbacks = [],
retries = 10,
updateDelay = 1,
ready,
update;

/**
* Checks if provided callback already exists in the callbacks list.
*
* @param {Object} callback - Callback object to be checked.
* @returns {Boolean}
*/
function isSubscribed(callback) {
return !!_.findWhere(callbacks, callback);
}

/**
* Checks if provided module is rejected during load.
*
* @param {Object} module - Module to be checked.
* @return {Boolean}
*/
function isRejected(module) {
return registry[module.id] && (registry[module.id].inited || registry[module.id].error);
}

/**
* Checks if provided module has unresolved dependencies.
*
* @param {Object} module - Module to be checked.
* @returns {Boolean}
*/
function isPending(module) {
if (!module.depCount) {
return false;
}

return module.depCount > _.filter(module.depMaps, isRejected).length;
}

/**
* Checks if requirejs's registry object contains pending modules.
*
* @returns {Boolean}
*/
function hasPending() {
return _.some(registry, isPending);
}

/**
* Checks if 'resolver' module is in ready
* state and that there are no pending modules.
*
* @returns {Boolean}
*/
function isReady() {
return ready && !hasPending();
}

/**
* Invokes provided callback handler.
*
* @param {Object} callback
*/
function invoke(callback) {
callback.handler.call(callback.ctx);
}

/**
* Sets 'resolver' module to a ready state
* and invokes pending callbacks.
*/
function resolve() {
ready = true;

callbacks.splice(0).forEach(invoke);
}

/**
* Drops 'ready' flag and runs the update process.
*/
function tick() {
ready = false;

update(retries);
}

/**
* Adds callback which will be invoked
* when all of the pending modules are initiated.
*
* @param {Function} handler - 'Ready' event handler function.
* @param {Object} [ctx] - Optional context with which handler
* will be invoked.
*/
function subscribe(handler, ctx) {
var callback = {
handler: handler,
ctx: ctx
};

if (!isSubscribed(callback)) {
callbacks.push(callback);

if (isReady()) {
_.defer(tick);
}
}
}

/**
* Checks for all modules to be initiated
* and invokes pending callbacks if it's so.
*
* @param {Number} [retry] - Number of retries
* that will be used to repeat the 'update' function
* invokation in case if there are no pending requests.
*/
update = _.debounce(function (retry) {
if (!hasPending()) {
retry ? update(--retry) : resolve();
}
}, updateDelay);

/**
* Overrides requirejs's original 'execCb' method
* in order to track pending modules.
*
* @returns {*} Result of original method call.
*/
context.execCb = function () {
var exported = execCb.apply(context, arguments);

tick();

return exported;
};

return subscribe;
});