0

I have been experimenting with the Hot Towel SPA and was successful in getting a view model and view to work using the ko.observables. The results from a call to the Breeze executeQuery are loaded into the observable using myObservable(data.results) and I see the results in the view.

Having read about the upcoming changes to Durandal I thought I would try to use the observables plugin. My problem is that the Breeze results are no longer showing up in my view. I've read the 'Binding Plain Javascript Objects' documentation in Durandal but this doesn't help me with Breeze and the 'Upgrading to Durandal 2.0' by John Papa also does not elaborate.

How do you get the results from a Breeze EntityQuery into the observable when using observable plugin?

Can someone point me in the right direction?

Alan Rutter
  • 321
  • 4
  • 16

2 Answers2

0

This is a good question for Rob, the author of Durandal. When last he was working on this, there was something he intended to do to make Breeze happy. Not sure how he left it.

Ward
  • 17,793
  • 4
  • 37
  • 53
0

Definitely one for Rob. I shall ask as well. In the meantime I am working on a project where I'm using these techs together so might be able to provide a pointer:

You can load breeze entities into plain javascript properties and Durandal will convert the property into an observable. However it will be a container for the knockout observables delivered by breeze so you need to code accordingly.

In the example below I'm using typescript and the unit of work pattern, but it should be somewhat familiar - the unit of work function here returns a promise from executeQuery:

public respondent: Respondent;

private loadData(id: string){

var self = this;

this.uow.respondents.withId(id).then(
    function(data : Respondent){
         self.Respondent = data;
    }
).fail(erorrHandler)

};

This works for me, for now. The only side effect is that from my limited experience I could not get durandal and knockout to play together in computed observables or custom bindings - so I had to use different solutions in places (kind of defeating the object!!).

@Ward - I think you can over-ride breeze turning its entities into observables and let durandal handle it (is this the case with Angular?) - but I don't know if this would have side-effects for other breeze goodies like tracking changes behind the scenes.

One other thing to note, is that if you do anything to the Durandal Binder after the observables plugin is invoked (like add an i18n libary) you need to re-include the original binding settings so as not to overwrite them.

Jeremy Noble
  • 183
  • 1
  • 13