]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-mode/node_modules/grim/node_modules/emissary/lib/subscription.js
b1d749fdb46b4c1480953f98accbf9597d10d857
[rbdr/dotfiles] / atom / packages / vim-mode / node_modules / grim / node_modules / emissary / lib / subscription.js
1 (function() {
2 var Emitter, Subscription,
3 __hasProp = {}.hasOwnProperty,
4 __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
5
6 Emitter = require('./emitter');
7
8 module.exports = Subscription = (function(_super) {
9 __extends(Subscription, _super);
10
11 Subscription.prototype.cancelled = false;
12
13 function Subscription(emitter, eventNames, handler) {
14 this.emitter = emitter;
15 this.eventNames = eventNames;
16 this.handler = handler;
17 }
18
19 Subscription.prototype.off = function() {
20 return this.dispose();
21 };
22
23 Subscription.prototype.dispose = function() {
24 var unsubscribe, _ref;
25 if (this.cancelled) {
26 return;
27 }
28 unsubscribe = (_ref = this.emitter.off) != null ? _ref : this.emitter.removeListener;
29 unsubscribe.call(this.emitter, this.eventNames, this.handler);
30 this.emitter = null;
31 this.handler = null;
32 this.cancelled = true;
33 return this.emit('cancelled');
34 };
35
36 return Subscription;
37
38 })(Emitter);
39
40 }).call(this);