Cleanup knockout.js

- Remove AMD
- Manually removed closure-compiler polyfill for Object.entries
This commit is contained in:
djmaze 2020-10-05 13:46:19 +02:00
parent 72ed2b08b2
commit 07857a06a9
4 changed files with 126 additions and 197 deletions

View file

@ -42,9 +42,7 @@
'loadComponent': (componentName, config, callback) => {
var errorCallback = makeErrorCallback(componentName);
possiblyGetConfigFromAmd(errorCallback, config, loadedConfig =>
resolveConfig(componentName, errorCallback, loadedConfig, callback)
);
resolveConfig(componentName, errorCallback, config, callback);
},
'loadTemplate': (componentName, templateConfig, callback) =>
@ -75,23 +73,19 @@
viewModelConfig = config['viewModel'];
if (templateConfig) {
possiblyGetConfigFromAmd(errorCallback, templateConfig, loadedConfig =>
ko.components._getFirstResultFromLoaders('loadTemplate', [componentName, loadedConfig], resolvedTemplate => {
result['template'] = resolvedTemplate;
tryIssueCallback();
})
);
ko.components._getFirstResultFromLoaders('loadTemplate', [componentName, templateConfig], resolvedTemplate => {
result['template'] = resolvedTemplate;
tryIssueCallback();
});
} else {
tryIssueCallback();
}
if (viewModelConfig) {
possiblyGetConfigFromAmd(errorCallback, viewModelConfig, loadedConfig =>
ko.components._getFirstResultFromLoaders('loadViewModel', [componentName, loadedConfig], resolvedViewModel => {
result[createViewModelKey] = resolvedViewModel;
tryIssueCallback();
})
);
ko.components._getFirstResultFromLoaders('loadViewModel', [componentName, viewModelConfig], resolvedViewModel => {
result[createViewModelKey] = resolvedViewModel;
tryIssueCallback();
});
} else {
tryIssueCallback();
}
@ -161,24 +155,6 @@
throw 'Template Source Element not a <template>';
}
function possiblyGetConfigFromAmd(errorCallback, config, callback) {
if (typeof config['require'] === 'string') {
// The config is the value of an AMD module
if (amdRequire || window['require']) {
(amdRequire || window['require'])([config['require']], module => {
if (module && typeof module === 'object' && module.__esModule && module['default']) {
module = module['default'];
}
callback(module);
});
} else {
errorCallback('Uses require, but no AMD loader is present');
}
} else {
callback(config);
}
}
function makeErrorCallback(componentName) {
return message => {
throw new Error('Component \'' + componentName + '\': ' + message)