File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ Thumbs.db
1010.build *
1111.npm
1212node_modules
13+ npm-debug.log
1314
1415# IDE's #
1516# ########
Original file line number Diff line number Diff line change @@ -125,6 +125,11 @@ angular.module(name, [
125125
126126 // Binds an object or a function to the provided context and digest it once it is invoked
127127 $$Core . $bindToContext = function ( context , fn ) {
128+ if ( _ . isFunction ( context ) ) {
129+ fn = context ;
130+ context = this ;
131+ }
132+
128133 return $$utils . bind ( fn , context , this . $$throttledDigest . bind ( this ) ) ;
129134 } ;
130135
Original file line number Diff line number Diff line change @@ -340,5 +340,42 @@ describe('angular-meteor.core', function() {
340340 scope . applyMethod ( 'method' , [ 'foo' , 'bar' ] , angular . noop ) ;
341341 } ) ;
342342 } ) ;
343+
344+ describe ( '$bindToContext()' , function ( ) {
345+ var scope ;
346+
347+ beforeEach ( function ( ) {
348+ scope = $rootScope . $new ( ) ;
349+ } ) ;
350+
351+ afterEach ( function ( ) {
352+ scope . $destroy ( ) ;
353+ } ) ;
354+
355+ it ( 'should bind a function to scope and digest once invoked' , function ( ) {
356+ var fn = jasmine . createSpy ( 'function' ) ;
357+ scope . $digest = jasmine . createSpy ( 'digest' ) ;
358+
359+ var boundFn = scope . $bindToContext ( fn ) ;
360+ boundFn ( 1 , 2 , 3 ) ;
361+
362+ expect ( fn ) . toHaveBeenCalled ( ) ;
363+ expect ( fn . calls . mostRecent ( ) . object ) . toEqual ( scope ) ;
364+ expect ( fn . calls . mostRecent ( ) . args ) . toEqual ( [ 1 , 2 , 3 ] ) ;
365+ } ) ;
366+
367+ it ( 'should bind the function to a custom scope if specified' , function ( ) {
368+ var fn = jasmine . createSpy ( 'function' ) ;
369+ scope . $digest = jasmine . createSpy ( 'digest' ) ;
370+
371+ var context = { } ;
372+ var boundFn = scope . $bindToContext ( context , fn ) ;
373+ boundFn ( 1 , 2 , 3 ) ;
374+
375+ expect ( fn ) . toHaveBeenCalled ( ) ;
376+ expect ( fn . calls . mostRecent ( ) . object ) . toEqual ( context ) ;
377+ expect ( fn . calls . mostRecent ( ) . args ) . toEqual ( [ 1 , 2 , 3 ] ) ;
378+ } ) ;
379+ } ) ;
343380 } ) ;
344381} ) ;
You can’t perform that action at this time.
0 commit comments