1 define("dojo/request/notify", ['../Evented', '../_base/lang', './util'], function(Evented, lang, util){
5 // Global notification API for dojo/request. Notifications will
6 // only be emitted if this module is required.
8 // | require('dojo/request', 'dojo/request/notify',
9 // | function(request, notify){
10 // | notify('load', function(response){
11 // | if(response.url === 'someUrl.html'){
12 // | console.log('Loaded!');
15 // | request.get('someUrl.html');
22 var hub = lang.mixin(new Evented, {
23 onsend: function(data){
29 _onload: function(data){
30 this.emit('done', data);
32 _onerror: function(data){
33 this.emit('done', data);
35 _ondone: function(data){
41 emit: function(type, event){
42 var result = Evented.prototype.emit.apply(this, arguments);
44 // After all event handlers have run, run _on* handler
45 if(this['_on' + type]){
46 this['_on' + type].apply(this, slice.call(arguments, 1));
52 function notify(type, listener){
54 // Register a listener to be notified when an event
55 // in dojo/request happens.
57 // The event to listen for. Events emitted: "start", "send",
58 // "load", "error", "done", "stop".
59 // listener: Function?
60 // A callback to be run when an event happens.
62 // A signal object that can be used to cancel the listener.
63 // If remove() is called on this signal object, it will
64 // stop the listener from being executed.
65 return hub.on(type, listener);
67 notify.emit = function(type, event, cancel){
68 return hub.emit(type, event, cancel);
71 // Attach notify to dojo/request/util to avoid
72 // try{ require('./notify'); }catch(e){}
73 return util.notify = notify;