@@ -4,27 +4,31 @@ var ngMeteorCollections = angular.module('ngMeteor.collections', []);
44ngMeteorCollections . 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
4853var AngularMeteorCollection = function ( collection , $q , selector , options ) {
4954 var self = collection . find ( selector , options ) . fetch ( ) ;
5055
0 commit comments