Throttle knockout check

I just noticed that using a throttle expander leads to the fact that fault tolerance cancels work. Is there any way to solve this problem?

var viewModel = { label1: ko.observable('label1').extend({required: true}), label2: ko.observable('label2').extend({required: true, throttle: 1}), }; ko.applyBindings(viewModel); 

jsFiddle: http://jsfiddle.net/rWqkC/

+4
source share
2 answers

In this case, the order of the extenders matters because the throttle expander returns a new ko.dependentObservable , so if you have required , then it will apply to the wrong observable.

Change the order and it should work:

 ko.observable('label2').extend({throttle: 500, required: true }), 

But since the execution of the expander in the order of declaration of the property is not really defined, you are safer if you use two extensions in this case:

 ko.observable('label2').extend({throttle: 500}).extend({required: true }) 

Demo script.

+7
source

For those who find this answer:

If you are using the Knockout version after 3.1.0, consider using the rateLimit extender . (rateLimit instead of gas)

0
source

Source: https://habr.com/ru/post/1444600/


All Articles