3

I wrote a custom binding that will perform like if binding at the first, and work as visible binding on the next.

ko.bindingHandlers.visibleIf = {
   init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)
   {
      // Doing stuff here
      // ...

      return ko.bindingHandlers.if.init.apply(this, arguments);
   },
   update: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)
   {
       // Doing stuff here
       // ...

       ko.bindingHandlers.if.update.apply(this, arguments);
    }
};

I used to wrap both of if.init and if.update and it works fine on KO 3.0, I just noticed it was removed on KO 3.1.

It is possible to wrap if.update function on KO 3.1 ? or do you have other suggestions that could help to achieve this?

Greatly appreciate it, Thanks.

Fariz Azmi
  • 713
  • 1
  • 6
  • 21
  • 2
    You can just remove the `ko.bindingHandlers.if.update.apply(this, arguments);` line and your binding should work fine with KO 3.1. – nemesv Mar 26 '14 at 11:18
  • Yes, it will work properly after removing the code, but it still will be act the same as a `if binding`. – Fariz Azmi Mar 27 '14 at 08:17

1 Answers1

0

You can add a property to your wrapper function that tells you if the IF-binding was fired before and/or if it has rendered its childs already. Then you can do exactly the same operations as you would have done with the former update callback.

Ronald Hulshof
  • 1,986
  • 16
  • 22