emberx-xml-http-request
emberx-xml-http-request copied to clipboard
Actions for XHR events
Sometimes you need to provide tracking of XHR events outside of your templates. For example, you might want to show a flash message when you're finished, or whenever there is an error.
We should fire an action for every major XHR event
Example:
{{#x-xml-http-request on-error=(flash "An error occurred") on-abort=(flash "Request cancelled") as |xhr|}}
{{! other stuff}}
{{/x-xml-http-request}}
This would address some of the concerns in #10
For those waiting on this functionality:
import Ember from 'ember';
import RequestComponent from 'emberx-xml-http-request/components/x-xml-http-request';
const { K } = Ember;
export default RequestComponent.extend({
'on-load': K,
'on-abort': K,
'on-error': K,
request: Ember.computed(function() {
return this._bindToXHREvents(this._super(...arguments));
}),
_bindToXHREvents(request) {
request.state.xhr.onload = this.get('on-load');
request.state.xhr.onabort = this.get('on-abort');
request.state.xhr.onerror = this.get('on-error');
return request;
}
});
I'd merge that PR ASAP :D