How to use Knockout-ES5 plugin with Breeze and Durandal

696 Views Asked by At
2

There are 2 best solutions below

0
Brendan On BEST ANSWER

The selected answer to this post takes the approach of:

  • using Breeze's built in BackingStore modelLibrary (instead off the Knockout modelLibrary)
  • making entities observable "as required" using the ES5 plugin by effectively calling ko.track(entity._backingStore) when a user indicates they want to edit a record.

This has the advantage of being much lighter for long lists of entities by not making them observable until they need to be. The ES5 plugin adds the benefit that the bindings in HTML don't need to change between the non-observable entities and the observable ones (as the brackets are not required).

If you required all entities to be "ES5" observable by default then you'd probably be best to write a custom modelLibrary adapter - take a look in the Breeze debug file (or source) to see the three built in adapters: backingStore, backbone, and ko as examples.

0
EisenbergEffect On

For Durandal, you can hook into the view model binder's beforeBind hook to automatically have Steve's plugin convert your object just before it is bound. This may not work flawlessly, I haven't tried it myself. Also, bear in mind that his plugin does not convert full object graphs, only the basic properties on the object. So, binding in this way probably won't work 100% as you want.

Durandal 2.0 has it's own ES5 plugin that works correctly :) It's not released yet, but it's under source along with the rest of 2.0 if you want to live on the edge. Release is scheduled for mid August.

Regarding Breeze, I'm not sure.