]>
Commit | Line | Data |
---|---|---|
1 | (function() { | |
2 | var CompositeDisposable; | |
3 | ||
4 | module.exports = CompositeDisposable = (function() { | |
5 | CompositeDisposable.prototype.disposed = false; | |
6 | ||
7 | ||
8 | /* | |
9 | Section: Construction and Destruction | |
10 | */ | |
11 | ||
12 | function CompositeDisposable() { | |
13 | var disposable, _i, _len; | |
14 | this.disposables = []; | |
15 | for (_i = 0, _len = arguments.length; _i < _len; _i++) { | |
16 | disposable = arguments[_i]; | |
17 | this.add(disposable); | |
18 | } | |
19 | } | |
20 | ||
21 | CompositeDisposable.prototype.dispose = function() { | |
22 | var disposable, _i, _len, _ref; | |
23 | if (!this.disposed) { | |
24 | this.disposed = true; | |
25 | _ref = this.disposables; | |
26 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
27 | disposable = _ref[_i]; | |
28 | disposable.dispose(); | |
29 | } | |
30 | return this.clear(); | |
31 | } | |
32 | }; | |
33 | ||
34 | ||
35 | /* | |
36 | Section: Managing Disposables | |
37 | */ | |
38 | ||
39 | CompositeDisposable.prototype.add = function(disposable) { | |
40 | if (!this.disposed) { | |
41 | return this.disposables.push(disposable); | |
42 | } | |
43 | }; | |
44 | ||
45 | CompositeDisposable.prototype.remove = function(disposable) { | |
46 | var index; | |
47 | index = this.disposables.indexOf(disposable); | |
48 | if (index !== -1) { | |
49 | return this.disposables.splice(index, 1); | |
50 | } | |
51 | }; | |
52 | ||
53 | CompositeDisposable.prototype.clear = function() { | |
54 | return this.disposables.length = 0; | |
55 | }; | |
56 | ||
57 | return CompositeDisposable; | |
58 | ||
59 | })(); | |
60 | ||
61 | }).call(this); |