Switch from ko.computed to ko.pureComputed

This should provide performance and memory benefits over regular computed observables
This commit is contained in:
djmaze 2021-12-31 13:30:05 +01:00
parent ac2238a23f
commit 954de06f86
18 changed files with 55 additions and 37 deletions

View file

@ -2,6 +2,7 @@ import ko from 'ko';
import { pInt } from 'Common/Utils';
import { SaveSettingsStep } from 'Common/Enums';
import { AbstractComponent } from 'Component/Abstract';
import { koComputable } from 'External/ko';
class AbstractInput extends AbstractComponent {
/**
@ -18,7 +19,7 @@ class AbstractInput extends AbstractComponent {
this.labeled = null != params.label;
let size = params.size || 0;
let size = 0 < params.size ? 'span' + params.size : '';
if (this.trigger) {
const
classForTrigger = ko.observable(''),
@ -38,13 +39,13 @@ class AbstractInput extends AbstractComponent {
setTriggerState(this.trigger());
this.className = ko.computed(() =>
((0 < size ? 'span' + size : '') + ' settings-saved-trigger-input ' + classForTrigger()).trim()
this.className = koComputable(() =>
(size + ' settings-saved-trigger-input ' + classForTrigger()).trim()
);
this.disposable.push(this.trigger.subscribe(setTriggerState, this));
} else {
this.className = ko.computed(() => 0 < size ? 'span' + size : '');
this.className = size;
}
this.disposable.push(this.className);