From bf63f793541604dfa6ef316f153f4d9bc75c6025 Mon Sep 17 00:00:00 2001 From: Emmanuel Potvin Date: Thu, 9 Apr 2015 16:15:05 -0400 Subject: [PATCH 1/7] Fix for #282 --- modules/angular-meteor-object.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/modules/angular-meteor-object.js b/modules/angular-meteor-object.js index 39843e740..c8643599b 100644 --- a/modules/angular-meteor-object.js +++ b/modules/angular-meteor-object.js @@ -98,9 +98,21 @@ angularMeteorObject.factory('AngularMeteorObject', ['$q', '$meteorSubscribe', fu // A list of internals properties to not watch for, nor pass to the Document on update and etc. AngularMeteorObject.prototype.$$internalProps = [ - 'save', 'reset', '$$collection', '$$options', '$$id', '$$hashkey', '$$internalProps', 'subscribe', 'stop', 'autorunComputation', 'unregisterAutoBind', 'unregisterAutoDestroy', 'getRawObject' + 'save', 'reset', '$$collection', '$$options', '$$id', '$$hashkey', '$$internalProps', 'subscribe', 'stop', 'autorunComputation', 'unregisterAutoBind', 'unregisterAutoDestroy', 'getRawObject', + 'collection', '_eventEmitter' ]; + AngularMeteorObject.prototype.internalProps = function() { + var self = this; + var internalProps = [].concat(self.$$internalProps); + _.each(self, function(value, prop) { + if (angular.isFunction(self[prop])) { + internalProps.push(prop); + } + }); + return internalProps; + }; + return AngularMeteorObject; }]); @@ -110,9 +122,13 @@ angularMeteorObject.factory('$meteorObject', ['$rootScope', '$meteorUtils', 'Ang return function(collection, id, auto, options) { // Validate parameters - if (!(collection instanceof Meteor.Collection)) { - throw new TypeError("The first argument of $collection must be a Meteor.Collection object."); + if (!collection) { + throw new TypeError("The first argument of $meteorCollection is undefined."); + } + if (!angular.isFunction(collection.findOne)) { + throw new TypeError("The first argument of $meteorCollection must be a function or a have a findOne function property."); } + auto = auto !== false; // Making auto default true - http://stackoverflow.com/a/15464208/1426570 var data = new AngularMeteorObject(collection, id, options); @@ -123,7 +139,7 @@ angularMeteorObject.factory('$meteorObject', ['$rootScope', '$meteorUtils', 'Ang if (auto) { // Deep watches the model and performs autobind. data.unregisterAutoBind = $rootScope.$watch(function(){ - return _.omit(data, data.$$internalProps); + return _.omit(data, data.internalProps()); }, function (newItem, oldItem) { if (newItem) { var newItemId = newItem._id; From 3d6ce3a770f2e69186df747fdae5423b71741f98 Mon Sep 17 00:00:00 2001 From: Emmanuel Potvin Date: Fri, 10 Apr 2015 08:32:45 -0400 Subject: [PATCH 2/7] Fix for #282: Advanced internalProps for FS.File objects. --- modules/angular-meteor-meteorCollection.js | 10 +++++++++- modules/angular-meteor-object.js | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/angular-meteor-meteorCollection.js b/modules/angular-meteor-meteorCollection.js index 4fae67d0d..63673a2e0 100644 --- a/modules/angular-meteor-meteorCollection.js +++ b/modules/angular-meteor-meteorCollection.js @@ -242,7 +242,15 @@ angularMeteorCollections.factory('$meteorCollection', ['$q', '$meteorSubscribe', realOldItems = _.without(ngCollection, 'UPDATING_FROM_SERVER'); return 'UPDATING_FROM_SERVER'; } - return _.without(ngCollection, 'UPDATING_FROM_SERVER'); + return _.without(_.map(ngCollection, function(object) { + var internalProps = ['collection']; + _.each(object, function (value, prop) { + if (angular.isFunction(object[prop])) { + internalProps.push(prop); + } + }); + return _.omit(object, internalProps); + }), 'UPDATING_FROM_SERVER'); }, function (newItems, oldItems) { if (newItems == 'UPDATING_FROM_SERVER') return; diff --git a/modules/angular-meteor-object.js b/modules/angular-meteor-object.js index c8643599b..564068a59 100644 --- a/modules/angular-meteor-object.js +++ b/modules/angular-meteor-object.js @@ -21,7 +21,7 @@ angularMeteorObject.factory('AngularMeteorObject', ['$q', '$meteorSubscribe', fu AngularMeteorObject.prototype.getRawObject = function () { var self = this; - return angular.copy(_.omit(self, self.$$internalProps)); + return angular.copy(_.omit(self, self.internalProps())); }; AngularMeteorObject.prototype.subscribe = function () { @@ -37,7 +37,7 @@ angularMeteorObject.factory('AngularMeteorObject', ['$q', '$meteorSubscribe', fu if (self) if (self._id){ - var updates = docs? docs : angular.copy(_.omit(self, '_id', self.$$internalProps)); + var updates = docs? docs : angular.copy(_.omit(self, '_id', self.internalProps())); collection.update( {_id: self._id}, { $set: updates }, @@ -72,7 +72,7 @@ angularMeteorObject.factory('AngularMeteorObject', ['$q', '$meteorSubscribe', fu } } } else { - for (prop in _.omit(self, self.$$internalProps)) { + for (prop in _.omit(self, self.internalProps())) { delete self[prop]; } } From f49394ff44d14cb9169fab68af1d95f5bf082633 Mon Sep 17 00:00:00 2001 From: Emmanuel Potvin Date: Fri, 24 Apr 2015 12:25:17 -0400 Subject: [PATCH 3/7] Fix for internalProps removed --- modules/angular-meteor-meteorCollection.js | 5 ----- modules/angular-meteor-object.js | 6 +++--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/modules/angular-meteor-meteorCollection.js b/modules/angular-meteor-meteorCollection.js index 092cf00f0..b706dd1c6 100644 --- a/modules/angular-meteor-meteorCollection.js +++ b/modules/angular-meteor-meteorCollection.js @@ -241,11 +241,6 @@ angularMeteorCollections.factory('$meteorCollection', ['AngularMeteorCollection' } return _.without(_.map(ngCollection, function(object) { var internalProps = ['collection']; - _.each(object, function (value, prop) { - if (angular.isFunction(object[prop])) { - internalProps.push(prop); - } - }); return _.omit(object, internalProps); }), 'UPDATING_FROM_SERVER'); }, function (newItems, oldItems) { diff --git a/modules/angular-meteor-object.js b/modules/angular-meteor-object.js index ee22b9c21..6a96271d2 100644 --- a/modules/angular-meteor-object.js +++ b/modules/angular-meteor-object.js @@ -6,7 +6,7 @@ angularMeteorObject.factory('AngularMeteorObject', ['$q', '$meteorSubscribe', fu AngularMeteorObject.getRawObject = function () { var self = this; - return angular.copy(_.omit(self, self.internalProps())); + return angular.copy(_.omit(self, self.$$internalProps)); }; AngularMeteorObject.subscribe = function () { @@ -22,7 +22,7 @@ angularMeteorObject.factory('AngularMeteorObject', ['$q', '$meteorSubscribe', fu if (self) if (self._id){ - var updates = docs? docs : angular.copy(_.omit(self, '_id', self.internalProps())); + var updates = docs? docs : angular.copy(_.omit(self, '_id', self.$$internalProps)); collection.update( {_id: self._id}, { $set: updates }, @@ -56,7 +56,7 @@ angularMeteorObject.factory('AngularMeteorObject', ['$q', '$meteorSubscribe', fu } } } else { - for (prop in _.omit(self, self.internalProps())) { + for (prop in _.omit(self, self.$$internalProps)) { delete self[prop]; } } From 22cb6d34e86f982248bf9ea4ab3faf7eeaab894a Mon Sep 17 00:00:00 2001 From: Emmanuel Potvin Date: Fri, 24 Apr 2015 12:37:46 -0400 Subject: [PATCH 4/7] Fix for internalProps removed --- modules/angular-meteor-object.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/modules/angular-meteor-object.js b/modules/angular-meteor-object.js index 6a96271d2..170f9ef72 100644 --- a/modules/angular-meteor-object.js +++ b/modules/angular-meteor-object.js @@ -86,17 +86,6 @@ angularMeteorObject.factory('AngularMeteorObject', ['$q', '$meteorSubscribe', fu 'collection', '_eventEmitter' ]; - AngularMeteorObject.internalProps = function() { - var self = this; - var internalProps = [].concat(AngularMeteorObject.$$internalProps); - _.each(self, function(value, prop) { - if (angular.isFunction(self[prop])) { - internalProps.push(prop); - } - }); - return internalProps; - }; - var createAngularMeteorObject = function(collection, id, options){ // Make data not be an object so we can extend it to preserve // Collection Helpers and the like @@ -137,7 +126,7 @@ angularMeteorObject.factory('$meteorObject', ['$rootScope', '$meteorUtils', 'Ang if (auto) { // Deep watches the model and performs autobind. data.unregisterAutoBind = $rootScope.$watch(function(){ - return _.omit(data, data.internalProps()); + return _.omit(data, data.$$internalProps); }, function (newItem, oldItem) { if (newItem !== oldItem && newItem) { var newItemId = newItem._id; From 0e4455648b551fe53e9805d999e5ddae78e5aec5 Mon Sep 17 00:00:00 2001 From: Tally Barak Date: Thu, 21 May 2015 16:11:44 +0300 Subject: [PATCH 5/7] mongo documents with ObjectId Retrieve documents that are stored with object Ids --- .../angular-meteor/client/views/api/api.meteorObject.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.docs/angular-meteor/client/views/api/api.meteorObject.html b/.docs/angular-meteor/client/views/api/api.meteorObject.html index 62ed25e50..f9eb345b6 100644 --- a/.docs/angular-meteor/client/views/api/api.meteorObject.html +++ b/.docs/angular-meteor/client/views/api/api.meteorObject.html @@ -24,6 +24,11 @@ $meteor.object(collection, selector, auto) $scope.$meteorObject(collection, selector, auto) + + If you documents are saved with objects IDs (and not strings: see here ), +you should use new Mongo.objectID to retieve the object. + + ### Arguments @@ -129,3 +134,6 @@ + + + From 6aff689e9506d33c376ce01bdcc8dd712534c66b Mon Sep 17 00:00:00 2001 From: Tally Barak Date: Thu, 21 May 2015 17:14:18 +0300 Subject: [PATCH 6/7] objectId code example + typo fix --- .../client/views/api/api.meteorObject.html | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.docs/angular-meteor/client/views/api/api.meteorObject.html b/.docs/angular-meteor/client/views/api/api.meteorObject.html index f9eb345b6..51c742130 100644 --- a/.docs/angular-meteor/client/views/api/api.meteorObject.html +++ b/.docs/angular-meteor/client/views/api/api.meteorObject.html @@ -14,8 +14,7 @@ Finds the first document that matches the selector, as ordered by sort and skip options. Wraps [collection.findOne](http://docs.meteor.com/#/full/findone) -Calling $scope.$meteorObject is exactly the same but additionally it will automatically stop the object when the scope is destroyed. -Therefor this is the recommended method. +Calling $scope.$meteorObject is exactly the same but additionally it will automatically stop the object when the scope is destroyed; therefore this is the recommended method. ---- @@ -24,11 +23,12 @@ $meteor.object(collection, selector, auto) $scope.$meteorObject(collection, selector, auto) - - If you documents are saved with objects IDs (and not strings: see here ), -you should use new Mongo.objectID to retieve the object. - + If you documents are saved with objects IDs (and not strings: see here ), +you should use new Mongo.objectID to retieve the object. + + $meteor.object (collection, new Meteor.ObjectID (stringId), auto); + ### Arguments @@ -109,6 +109,7 @@ $scope.party = $meteor.object(Parties, $stateParams.partyId); + $scope.partyNotAuto = $scope.$meteorObject(Parties, $stateParams.partyId, false); $scope.save = function() { From de97110e83b620fabc96aedae739bb43fa349d6d Mon Sep 17 00:00:00 2001 From: Emmanuel Potvin Date: Thu, 21 May 2015 11:41:32 -0400 Subject: [PATCH 7/7] Revert collection change --- modules/angular-meteor-meteorCollection.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/angular-meteor-meteorCollection.js b/modules/angular-meteor-meteorCollection.js index b706dd1c6..d436d68d4 100644 --- a/modules/angular-meteor-meteorCollection.js +++ b/modules/angular-meteor-meteorCollection.js @@ -239,10 +239,7 @@ angularMeteorCollections.factory('$meteorCollection', ['AngularMeteorCollection' realOldItems = _.without(ngCollection, 'UPDATING_FROM_SERVER'); return 'UPDATING_FROM_SERVER'; } - return _.without(_.map(ngCollection, function(object) { - var internalProps = ['collection']; - return _.omit(object, internalProps); - }), 'UPDATING_FROM_SERVER'); + return _.without(ngCollection, 'UPDATING_FROM_SERVER'); }, function (newItems, oldItems) { if (newItems == 'UPDATING_FROM_SERVER') return;