Skip to content

Commit d3a3f4d

Browse files
committed
Minor code style Improvements
1 parent 6dfb814 commit d3a3f4d

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

modules/ngMeteor-collections.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,31 @@ var ngMeteorCollections = angular.module('ngMeteor.collections', []);
44
ngMeteorCollections.factory('$collection', ['$q', 'HashKeyCopier',
55
function ($q, HashKeyCopier) {
66
return function (collection, selector, options) {
7-
if (!selector) selector = {};
7+
selector = selector || {};
8+
89
if (!(collection instanceof Meteor.Collection)) {
910
throw new TypeError("The first argument of $collection must be a Meteor.Collection object.");
1011
}
12+
1113
return {
1214
bind: function (scope, model, auto) {
1315
auto = auto || false; // Sets default binding type.
1416
if (!(typeof auto === 'boolean')) { // Checks if auto is a boolean.
1517
throw new TypeError("The third argument of bind must be a boolean.");
1618
}
1719

18-
Deps.autorun(function (self) {
20+
var comp = Deps.autorun(function (self) {
1921
var ngCollection = new AngularMeteorCollection(collection, $q, selector, options);
2022

2123
// Bind collection to model in scope. Transfer $$hashKey based on _id.
24+
// TODO Make this more efficient
2225
scope[model] = HashKeyCopier.copyHashKeys(scope[model], ngCollection, ["_id"]);
2326

24-
if (!scope.$$phase) scope.$apply(); // Update bindings in scope.
25-
scope.$on('$destroy', function () {
26-
self.stop(); // Stop computation if scope is destroyed.
27-
});
27+
if (!scope.$$phase) scope.$apply();
28+
});
29+
30+
scope.$on('$destroy', function () {
31+
comp.stop(); // Stop computation if scope is destroyed.
2832
});
2933

3034
if (auto) { // Deep watches the model and performs autobind.
@@ -45,6 +49,7 @@ ngMeteorCollections.factory('$collection', ['$q', 'HashKeyCopier',
4549
}
4650
]);
4751

52+
// Ctor
4853
var AngularMeteorCollection = function (collection, $q, selector, options) {
4954
var self = collection.find(selector, options).fetch();
5055

versions.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"dependencies": [
3+
[
4+
"jquery",
5+
"1.0.0"
6+
],
7+
[
8+
"meteor",
9+
"1.0.2"
10+
],
11+
[
12+
"underscore",
13+
"1.0.0"
14+
]
15+
],
16+
"pluginDependencies": [],
17+
"toolVersion": "meteor-tool@1.0.26",
18+
"format": "1.0"
19+
}

0 commit comments

Comments
 (0)