Drop Knockout.js loading components asynchronous

https://knockoutjs.com/documentation/component-registration.html#controlling-synchronousasynchronous-loading
This commit is contained in:
the-djmaze 2022-09-12 22:31:05 +02:00
parent ef8b1f40e4
commit d1f71508fe
2 changed files with 4 additions and 12 deletions

View file

@ -8,7 +8,7 @@ knockoutDebugCallback([
'src/utils.domNodeDisposal.js',
// 'src/utils.domManipulation.js',
// 'src/memoization.js',
'src/tasks.js',
// 'src/tasks.js',
'src/subscribables/extenders.js',
'src/subscribables/subscribable.js',
'src/subscribables/dependencyDetection.js',

View file

@ -5,11 +5,10 @@
ko.components = {
get: (componentName, callback) => {
if (loadedDefinitionsCache.has(componentName)) {
ko.tasks.schedule(() => callback(loadedDefinitionsCache.get(componentName)));
callback(loadedDefinitionsCache.get(componentName));
} else {
// Join the loading process that is already underway, or start a new one.
var subscribable = loadingSubscribablesCache[componentName],
completedAsync;
var subscribable = loadingSubscribablesCache[componentName];
if (subscribable) {
subscribable.subscribe(callback);
} else {
@ -27,15 +26,8 @@
//
// You can bypass the 'always asynchronous' feature by putting the synchronous:true
// flag on your component configuration when you register it.
if (completedAsync) {
// Note that notifySubscribers ignores any dependencies read within the callback.
// See comment in loaderRegistryBehaviors.js for reasoning
subscribable.notifySubscribers(definition);
} else {
ko.tasks.schedule(() => subscribable.notifySubscribers(definition));
}
subscribable.notifySubscribers(definition);
});
completedAsync = true;
}
}
},