handle.js revision 3c3ca86f00a79df2bb2a69cd26d8c423d856bd6e
1247N/A/**
1247N/A * Return value from all subscribe operations
1247N/A * @class EventHandle
1247N/A * @constructor
1247N/A * @param {CustomEvent} evt the custom event.
1247N/A * @param {Subscriber} sub the subscriber.
1247N/A */
1247N/AY.EventHandle = function(evt, sub) {
1247N/A
1247N/A /**
1247N/A * The custom event
1247N/A *
1247N/A * @property evt
1247N/A * @type CustomEvent
1247N/A */
1247N/A this.evt = evt;
1247N/A
1247N/A /**
1247N/A * The subscriber object
1247N/A *
1247N/A * @property sub
1247N/A * @type Subscriber
1247N/A */
1247N/A this.sub = sub;
1247N/A};
1247N/A
1247N/AY.EventHandle.prototype = {
1247N/A batch: function(f, c) {
1247N/A f.call(c || this, this);
1247N/A if (Y.Lang.isArray(this.evt)) {
1247N/A Y.Array.each(this.evt, function(h) {
1247N/A h.batch.call(c || h, f);
1247N/A });
1247N/A }
1247N/A },
1247N/A
1247N/A /**
1247N/A * Detaches this subscriber
1247N/A * @method detach
1247N/A * @return {int} the number of detached listeners
1247N/A */
1247N/A detach: function() {
1247N/A var evt = this.evt, detached = 0, i;
1247N/A if (evt) {
1247N/A // Y.log('EventHandle.detach: ' + this.sub, 'info', 'Event');
1247N/A if (Y.Lang.isArray(evt)) {
1247N/A for (i = 0; i < evt.length; i++) {
1247N/A detached += evt[i].detach();
1247N/A }
1247N/A } else {
1247N/A evt._delete(this.sub);
1247N/A detached = 1;
1247N/A }
1247N/A
1247N/A }
1247N/A
1247N/A return detached;
1247N/A },
1247N/A
1247N/A /**
1247N/A * Monitor the event state for the subscribed event. The first parameter
1247N/A * is what should be monitored, the rest are the normal parameters when
1247N/A * subscribing to an event.
1247N/A * @method monitor
1247N/A * @param what {string} what to monitor ('attach', 'detach', 'publish').
1247N/A * @return {EventHandle} return value from the monitor event subscription.
1247N/A */
1247N/A monitor: function(what) {
1247N/A return this.evt.monitor.apply(this.evt, arguments);
1247N/A }
1247N/A};
1247N/A