viezel / napp.alloy.adapter.restapi

RestAPI Sync Adapter for Titanium Alloy Framework
197 stars 102 forks source link

access HTTPClient via this in the onxxx callbacks #33

Closed javenwang closed 10 years ago

javenwang commented 10 years ago

during the onload/onerror callback, we should use 'this' to access responseText and status or xhr will not be released. this commit will fix https://github.com/viezel/napp.alloy.adapter.restapi/issues/27

viezel commented 10 years ago

Why would you want that? Its more safe to reference the object itself rather than this.

javenwang commented 10 years ago

Hi @viezel , as mentioned in my comment, the xhr won't be released because there is a cycle reference between xhr and its onxxx callback. i think that is the reason causing https://github.com/viezel/napp.alloy.adapter.restapi/issues/27.

You can download the attachment from https://jira.appcelerator.org/browse/ALOY-915 and verify by yourself.

In Titanium document (http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.Network.HTTPClient-property-onload)

To access response data and headers, access the HTTPClient object itself (accessible as this during the callback, or the source property of the callback event).

viezel commented 10 years ago

fair enough.. ill merge it.