Skip to content

Commit

Permalink
Are you able to call subs.subscribe("mySub").stop() ? kadirahq#28
Browse files Browse the repository at this point in the history
  • Loading branch information
markshust committed Aug 2, 2016
1 parent 305cf5c commit d228036
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/sub_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ SubsManager.prototype.subscribe = function() {
var self = this;
if(Meteor.isClient) {
var args = _.toArray(arguments);
this._addSub(args);
var key = this._addSub(args);

return {
key: key,
ready: function() {
self.dep.depend();
return self._ready;
Expand Down Expand Up @@ -81,6 +82,21 @@ SubsManager.prototype._addSub = function(args) {
var index = _.indexOf(self._cacheList, sub);
self._cacheList.splice(index, 1);
self._cacheList.push(sub);

return hash;
};

SubsManager.prototype.unsubscribe = function(subKey) {
var sub = this._cacheMap[subKey];
var index = _.indexOf(this._cacheList, sub);

if (!sub || index == -1) {
return;
}

this._cacheList.splice(index, 1);
delete this._cacheMap[subKey];
this._reRunSubs();
};

SubsManager.prototype._reRunSubs = function() {
Expand Down

0 comments on commit d228036

Please sign in to comment.