Skip to content

Commit dfa3532

Browse files
committed
Make sure autobind is stopped immediately when the .stop() function is called , fixes meteor/simple-todos-angular#2
1 parent 70c0635 commit dfa3532

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

modules/angular-meteor-meteorCollection.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,10 @@ angularMeteorCollections.factory('AngularMeteorCollection', ['$q', '$meteorSubsc
219219
};
220220

221221
AngularMeteorCollection.stop = function () {
222-
if (this.unregisterAutoBind)
222+
if (this.unregisterAutoBind){
223+
this._isAutoBind = false;
223224
this.unregisterAutoBind();
225+
}
224226

225227
if (this.observeHandle)
226228
this.observeHandle.stop();
@@ -282,17 +284,21 @@ angularMeteorCollections.factory('$meteorCollection', ['AngularMeteorCollection'
282284

283285
function setAutoBind() {
284286
if (auto) { // Deep watches the model and performs autobind.
287+
ngCollection._isAutoBind = true;
285288
ngCollection.unregisterAutoBind = $rootScope.$watch(function () {
286289
if (ngCollection.UPDATING_FROM_SERVER) {
287290
return 'UPDATING_FROM_SERVER';
288291
}
289292
return angular.copy(_.without(ngCollection, 'UPDATING_FROM_SERVER'));
290293
}, function (newItems, oldItems) {
294+
if (ngCollection._isAutoBind == false)
295+
return;
291296
if (newItems === 'UPDATING_FROM_SERVER' ||
292297
oldItems === 'UPDATING_FROM_SERVER')
293298
return;
294299

295300
if (newItems !== oldItems) {
301+
ngCollection._isAutoBind = false;
296302
ngCollection.unregisterAutoBind();
297303

298304
updateCollection(ngCollection, oldItems, diffArrayFunc);

0 commit comments

Comments
 (0)