Replace deprecated Knockout throttle with new debounce extender

Replace admin general mainAttachmentLimit with input type="number"
This commit is contained in:
djmaze 2021-02-10 12:12:36 +01:00
parent 75b7176ada
commit 8c780ad353
18 changed files with 45 additions and 84 deletions

View file

@ -1,7 +1,6 @@
import 'External/ko'; import 'External/ko';
import ko from 'ko'; import ko from 'ko';
import { SaveSettingsStep } from 'Common/Enums'; import { SaveSettingsStep } from 'Common/Enums';
import { pInt } from 'Common/Utils';
ko.bindingHandlers.saveTrigger = { ko.bindingHandlers.saveTrigger = {
init: (element) => { init: (element) => {
@ -38,27 +37,6 @@ ko.extenders.idleTrigger = (target) => {
return target; return target;
}; };
ko.extenders.posInterer = (target, defaultVal) => {
const result = ko.computed({
read: target,
write: newValue => {
let val = pInt(newValue.toString(), defaultVal);
if (0 >= val) {
val = defaultVal;
}
if (val === target() && '' + val !== '' + newValue) {
target(val + 1);
}
target(val);
}
});
result(target());
return result;
};
// functions // functions
ko.observable.fn.idleTrigger = function() { ko.observable.fn.idleTrigger = function() {

View file

@ -237,32 +237,3 @@ ko.bindingHandlers.onEsc = {
ko.utils.domNodeDisposal.addDisposeCallback(element, () => element.removeEventListener('keyup', fn)); ko.utils.domNodeDisposal.addDisposeCallback(element, () => element.removeEventListener('keyup', fn));
} }
}; };
// extenders
ko.extenders.specialThrottle = (target, timeout) => {
timeout = parseInt(timeout, 10);
if (0 < timeout) {
let timer = 0,
valueForRead = ko.observable(!!target()).extend({ throttle: 10 });
return ko.computed({
read: valueForRead,
write: (bValue) => {
if (bValue) {
valueForRead(bValue);
} else if (valueForRead()) {
clearTimeout(timer);
timer = setTimeout(() => {
valueForRead(false);
timer = 0;
}, timeout);
} else {
valueForRead(bValue);
}
}
});
}
return target;
};

View file

@ -55,7 +55,7 @@ export class FilterConditionModel extends AbstractModel {
default: default:
return template + 'Default'; return template + 'Default';
} }
}, this); });
this.addSubscribables({ this.addSubscribables({
field: () => { field: () => {

View file

@ -275,7 +275,7 @@ export class SieveScriptModel extends AbstractModel
}); });
this.filters = ko.observableArray(); this.filters = ko.observableArray();
// this.saving = ko.observable(false).extend({ throttle: 200 }); // this.saving = ko.observable(false).extend({ debounce: 200 });
this.addSubscribables({ this.addSubscribables({
name: () => this.hasChanges(true), name: () => this.hasChanges(true),

View file

@ -57,7 +57,7 @@ export class GeneralAdminSettings {
this.mainAttachmentLimit = ko this.mainAttachmentLimit = ko
.observable(pInt(settingsGet('AttachmentLimit')) / (1024 * 1024)) .observable(pInt(settingsGet('AttachmentLimit')) / (1024 * 1024))
.extend({ posInterer: 25 }); .extend({ debounce: 500 });
this.uploadData = settingsGet('PhpUploadSizes'); this.uploadData = settingsGet('PhpUploadSizes');
this.uploadDataDesc = this.uploadDataDesc =
@ -77,7 +77,7 @@ export class GeneralAdminSettings {
this.languageFullName = ko.computed(() => convertLangName(this.language())); this.languageFullName = ko.computed(() => convertLangName(this.language()));
this.languageAdminFullName = ko.computed(() => convertLangName(this.languageAdmin())); this.languageAdminFullName = ko.computed(() => convertLangName(this.languageAdmin()));
this.languageAdminTrigger = ko.observable(SaveSettingsStep.Idle).extend({ throttle: 100 }); this.languageAdminTrigger = ko.observable(SaveSettingsStep.Idle).extend({ debounce: 100 });
} }
onBuild() { onBuild() {

View file

@ -23,7 +23,7 @@ export class ContactsUserSettings {
this.contactsSyncPass() this.contactsSyncPass()
].join('|') ].join('|')
) )
.extend({ throttle: 500 }); .extend({ debounce: 500 });
} }
onBuild() { onBuild() {

View file

@ -16,7 +16,7 @@ import { SieveScriptPopupView } from 'View/Popup/SieveScript';
export class FiltersUserSettings { export class FiltersUserSettings {
constructor() { constructor() {
this.scripts = SieveStore.scripts; this.scripts = SieveStore.scripts;
this.loading = ko.observable(false).extend({ throttle: 200 }); this.loading = ko.observable(false).extend({ debounce: 200 });
ko.addObservablesTo(this, { ko.addObservablesTo(this, {
serverError: false, serverError: false,

View file

@ -47,7 +47,7 @@ export class GeneralUserSettings {
this.allowLanguagesOnSettings = !!rl.settings.get('AllowLanguagesOnSettings'); this.allowLanguagesOnSettings = !!rl.settings.get('AllowLanguagesOnSettings');
this.languageFullName = ko.computed(() => convertLangName(this.language())); this.languageFullName = ko.computed(() => convertLangName(this.language()));
this.languageTrigger = ko.observable(SaveSettingsStep.Idle).extend({ throttle: 100 }); this.languageTrigger = ko.observable(SaveSettingsStep.Idle).extend({ debounce: 100 });
ko.addObservablesTo(this, { ko.addObservablesTo(this, {
mppTrigger: SaveSettingsStep.Idle, mppTrigger: SaveSettingsStep.Idle,

View file

@ -25,7 +25,7 @@ export class ThemesUserSettings {
this.capaUserBackground = ko.observable(rl.settings.capa(Capa.UserBackground)); this.capaUserBackground = ko.observable(rl.settings.capa(Capa.UserBackground));
this.themeTrigger = ko.observable(SaveSettingsStep.Idle).extend({ throttle: 100 }); this.themeTrigger = ko.observable(SaveSettingsStep.Idle).extend({ debounce: 100 });
this.theme.subscribe((value) => { this.theme.subscribe((value) => {
this.themesObjects.forEach(theme => { this.themesObjects.forEach(theme => {

View file

@ -3,7 +3,7 @@ import ko from 'ko';
class PackageAdminStore { class PackageAdminStore {
constructor() { constructor() {
this.packages = ko.observableArray(); this.packages = ko.observableArray();
this.packages.loading = ko.observable(false).extend({ throttle: 100 }); this.packages.loading = ko.observable(false).extend({ debounce: 100 });
ko.addObservablesTo(this, { ko.addObservablesTo(this, {
packagesReal: true, packagesReal: true,

View file

@ -3,7 +3,7 @@ import ko from 'ko';
class PluginAdminStore { class PluginAdminStore {
constructor() { constructor() {
this.plugins = ko.observableArray(); this.plugins = ko.observableArray();
this.plugins.loading = ko.observable(false).extend({ throttle: 100 }); this.plugins.loading = ko.observable(false).extend({ debounce: 100 });
this.plugins.error = ko.observable(''); this.plugins.error = ko.observable('');
} }
} }

View file

@ -9,7 +9,7 @@ class AccountUserStore {
}); });
this.accounts = ko.observableArray(); this.accounts = ko.observableArray();
this.accounts.loading = ko.observable(false).extend({ throttle: 100 }); this.accounts.loading = ko.observable(false).extend({ debounce: 100 });
this.getEmailAddresses = () => this.accounts.map(item => item ? item.email : null).filter(v => v); this.getEmailAddresses = () => this.accounts.map(item => item ? item.email : null).filter(v => v);

View file

@ -3,11 +3,11 @@ import ko from 'ko';
class ContactUserStore { class ContactUserStore {
constructor() { constructor() {
this.contacts = ko.observableArray(); this.contacts = ko.observableArray();
this.contacts.loading = ko.observable(false).extend({ throttle: 200 }); this.contacts.loading = ko.observable(false).extend({ debounce: 200 });
this.contacts.importing = ko.observable(false).extend({ throttle: 200 }); this.contacts.importing = ko.observable(false).extend({ debounce: 200 });
this.contacts.syncing = ko.observable(false).extend({ throttle: 200 }); this.contacts.syncing = ko.observable(false).extend({ debounce: 200 });
this.contacts.exportingVcf = ko.observable(false).extend({ throttle: 200 }); this.contacts.exportingVcf = ko.observable(false).extend({ debounce: 200 });
this.contacts.exportingCsv = ko.observable(false).extend({ throttle: 200 }); this.contacts.exportingCsv = ko.observable(false).extend({ debounce: 200 });
ko.addObservablesTo(this, { ko.addObservablesTo(this, {
allowContactsSync: false, allowContactsSync: false,

View file

@ -3,7 +3,7 @@ import ko from 'ko';
class IdentityUserStore { class IdentityUserStore {
constructor() { constructor() {
this.identities = ko.observableArray(); this.identities = ko.observableArray();
this.identities.loading = ko.observable(false).extend({ throttle: 100 }); this.identities.loading = ko.observable(false).extend({ debounce: 100 });
this.getIDS = () => this.identities.map(item => (item ? item.id() : null)).filter(value => null !== value); this.getIDS = () => this.identities.map(item => (item ? item.id() : null)).filter(value => null !== value);
} }

View file

@ -57,7 +57,7 @@ class MessageUserStore {
constructor() { constructor() {
this.staticMessage = new MessageModel(); this.staticMessage = new MessageModel();
this.messageList = ko.observableArray().extend({ rateLimit: 0 }); this.messageList = ko.observableArray().extend({ debounce: 0 });
ko.addObservablesTo(this, { ko.addObservablesTo(this, {
messageListCount: 0, messageListCount: 0,
@ -93,12 +93,12 @@ class MessageUserStore {
messageActiveDom: null messageActiveDom: null
}); });
this.messageListCompleteLoadingThrottle = ko.observable(false).extend({ throttle: 200 }); this.messageListCompleteLoadingThrottle = ko.observable(false).extend({ debounce: 200 });
this.messageListCompleteLoadingThrottleForAnimation = ko.observable(false).extend({ specialThrottle: 700 }); this.messageListCompleteLoadingThrottleForAnimation = ko.observable(false);
this.messageListDisableAutoSelect = ko.observable(false).extend({ falseTimeout: 500 }); this.messageListDisableAutoSelect = ko.observable(false).extend({ falseTimeout: 500 });
this.messageLoadingThrottle = ko.observable(false).extend({ throttle: 50 }); this.messageLoadingThrottle = ko.observable(false).extend({ debounce: 50 });
this.messageLoading = ko.computed(() => this.messageCurrentLoading()); this.messageLoading = ko.computed(() => this.messageCurrentLoading());
@ -184,10 +184,22 @@ class MessageUserStore {
} }
subscribers() { subscribers() {
let timer = 0, fn = this.messageListCompleteLoadingThrottleForAnimation;
this.messageListCompleteLoading.subscribe((value) => { this.messageListCompleteLoading.subscribe((value) => {
value = !!value; value = !!value;
this.messageListCompleteLoadingThrottle(value); this.messageListCompleteLoadingThrottle(value);
this.messageListCompleteLoadingThrottleForAnimation(value);
if (value) {
fn(value);
} else if (fn()) {
clearTimeout(timer);
timer = setTimeout(() => {
fn(value);
timer = 0;
}, 700);
} else {
fn(value);
}
}); });
this.messageList.subscribe( this.messageList.subscribe(

View file

@ -5,9 +5,9 @@ import ko from 'ko';
class TemplateUserStore { class TemplateUserStore {
constructor() { constructor() {
this.templates = ko.observableArray(); this.templates = ko.observableArray();
this.templates.loading = ko.observable(false).extend({ throttle: 100 }); this.templates.loading = ko.observable(false).extend({ debounce: 100 });
this.templatesNames = ko.observableArray().extend({ throttle: 1000 }); this.templatesNames = ko.observableArray().extend({ debounce: 1000 });
this.templatesNames.skipFirst = true; this.templatesNames.skipFirst = true;
this.subscribers(); this.subscribers();

View file

@ -202,8 +202,8 @@ class ComposePopupView extends AbstractViewPopup {
this.attachments = ko.observableArray(); this.attachments = ko.observableArray();
this.dragAndDropOver = ko.observable(false).extend({ throttle: 1 }); this.dragAndDropOver = ko.observable(false).extend({ debounce: 1 });
this.dragAndDropVisible = ko.observable(false).extend({ throttle: 1 }); this.dragAndDropVisible = ko.observable(false).extend({ debounce: 1 });
this.currentIdentity.extend({ this.currentIdentity.extend({
toggleSubscribe: [ toggleSubscribe: [

View file

@ -111,14 +111,14 @@
<div class="control-group"> <div class="control-group">
<label class="control-label" data-i18n="TAB_GENERAL/LABEL_ATTACHMENT_SIZE_LIMIT"></label> <label class="control-label" data-i18n="TAB_GENERAL/LABEL_ATTACHMENT_SIZE_LIMIT"></label>
<div class="controls"> <div class="controls">
<input type="number" min="1" step="1" class="span1" data-bind="textInput: mainAttachmentLimit"/>
&nbsp;
<span data-i18n="MB"></span>
&nbsp;
&nbsp;
<div data-bind="component: { <div data-bind="component: {
name: 'Input', name: 'SaveTrigger',
params: { params: { value: attachmentLimitTrigger }
label: 'MB',
value: mainAttachmentLimit,
trigger: attachmentLimitTrigger,
size: 1
}
}"></div> }"></div>
<br /> <br />
<br /> <br />