aurelia / http-client

A simple, restful, message-based wrapper around XMLHttpRequest.
MIT License
62 stars 59 forks source link

Member variable being changed during promise chain #70

Closed grantcarthew closed 9 years ago

grantcarthew commented 9 years ago

Hi Aurelia team,

Sorry to bother you but I am really at a loss as to what is happening with this issue I have and need some input from you. I have replicated the issue in a fork of the skeleton. It is acting a little different to the issue I have, but is still changing a saved value between one "then" and the next in a promise chain.

To see the issue clone this; https://github.com/grantcarthew/skeleton-navigation

npm/jspm install watch etc...

Open the browser, I am using Chrome, and open the dev tools. Switch the dev tools to the console tab. Click on the Flickr route.

Looking at the code you will see I have used the model and service design that Patrick Walters @PWKad has published on his blog. It is a really comfortable abstraction and I would like to keep using it.

The issue you will see in the console, and if you click on the Flickr.js file, is that "this.person" is being transformed from a PersonModel object into a generic object.

I have no idea why this is happening. It could be a number of things causing it. The most probable is that I have made a mistake somewhere.

I don't know how to fault find this either.

As I said, the issue you see here is slightly different to the one I have in my application. In my application the object is still a person model object, but the number values are changing to strings.

So in the first Then block, this.person = PersonModel { "thing": 123 }, then in the second Then block, this.person = PersonModel { "thing": "123" }. You will notice the quotes around the number in the second Then block. Again, this is not what you will see in the fork of the skeleton, but it is along the same lines.

Any help is greatly appreciated,

Regards,

Grant.

grantcarthew commented 9 years ago

OK, as I suspected. This was operator error. A nut loose on the keyboard. I'm not totally sure, but a guess is that the promise was not resolved when Aurelia bound the values. After reading through the documentation on Aurelia again, I noticed you can return a promise in the activate method, causing Aurelia to wait till the promise is resolved. After returning the promise, all was good.