mbest / knockout

My enhancements to Knockout
35 stars 4 forks source link

runafter binding break after knockout version 2.1.0 #25

Closed alextcl closed 10 years ago

alextcl commented 10 years ago

Hi, I was using your runafter bindinghandler,

the binding is working up to knockout version 2.1 http://jsfiddle.net/alextancl/W5KDE/1/

however, it break when using version 2.2 and above http://jsfiddle.net/alextancl/W5KDE/2/

could you please look into this

mbest commented 10 years ago

Knockout has progressively moved in the direction that bindings don't update each other. So "runafter" needs a little extra help to get all the dependencies.

ko.bindingHandlers.runafter = {
    update: function(element, valueAccessor, allBindingsAccessor) {
        // add dependency on all other bindings
        ko.toJS(allBindingsAccessor());
        setTimeout(function() {
            var value = valueAccessor();
            if (typeof value != 'function' || ko.isObservable(value))
                throw new Error('run must be used with a function');
            value(element);
        });
    }
};

http://jsfiddle.net/mbest/W5KDE/3/

mbest commented 10 years ago

I've also updated https://github.com/knockout/knockout/wiki/Bindings:-runafter

Thanks for letting me know about this.