Cleanup KnockoutJS a bit

This commit is contained in:
the-djmaze 2024-10-30 01:08:18 +01:00
parent 4cd5774257
commit bc6a2b67c0
4 changed files with 55 additions and 65 deletions

View file

@ -9,7 +9,7 @@ ko.selectExtensions = {
switch (element.nodeName) {
case 'OPTION':
return (element[hasDomDataExpandoProperty] === true)
? ko.utils.domData.get(element, ko.bindingHandlers.options.optionValueDomDataKey)
? ko.utils.domData.get(element, ko.bindingHandlers['options'].optionValueDomDataKey)
: element.value;
case 'SELECT':
return element.selectedIndex >= 0
@ -24,13 +24,13 @@ ko.selectExtensions = {
switch (element.nodeName) {
case 'OPTION':
if (typeof value === "string") {
ko.utils.domData.set(element, ko.bindingHandlers.options.optionValueDomDataKey, undefined);
ko.utils.domData.set(element, ko.bindingHandlers['options'].optionValueDomDataKey, undefined);
delete element[hasDomDataExpandoProperty];
element.value = value;
}
else {
// Store arbitrary object using DomData
ko.utils.domData.set(element, ko.bindingHandlers.options.optionValueDomDataKey, value);
ko.utils.domData.set(element, ko.bindingHandlers['options'].optionValueDomDataKey, value);
element[hasDomDataExpandoProperty] = true;
// Special treatment of numbers is just for backward compatibility. KO 1.2.1 wrote numerical values to element.value.

View file

@ -5,16 +5,11 @@
'init': (element, valueAccessor, ignored1, ignored2, bindingContext) => {
var currentViewModel,
currentLoadingOperationId,
afterRenderSub,
disposeAssociatedComponentViewModel = () => {
var currentViewModelDispose = currentViewModel && currentViewModel['dispose'];
if (typeof currentViewModelDispose === 'function') {
currentViewModelDispose.call(currentViewModel);
}
if (afterRenderSub) {
afterRenderSub['dispose']();
}
afterRenderSub = null;
currentViewModel = null;
// Any in-flight loading operation is no longer relevant, so make sure we ignore its completion
currentLoadingOperationId = null;