| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ Thumbs.db | |||
| 10 | 10 | .build* | |
| 11 | 11 | .npm | |
| 12 | 12 | node_modules | |
| 13 | + npm-debug.log | ||
| 13 | 14 | ||
| 14 | 15 | # IDE's # | |
| 15 | 16 | ######### | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -125,6 +125,11 @@ angular.module(name, [ | |||
| 125 | 125 | ||
| 126 | 126 | // Binds an object or a function to the provided context and digest it once it is invoked | |
| 127 | 127 | $$Core.$bindToContext = function(context, fn) { | |
| 128 | + if (_.isFunction(context)) { | ||
| 129 | + fn = context; | ||
| 130 | + context = this; | ||
| 131 | + } | ||
| 132 | + | ||
| 128 | 133 | return $$utils.bind(fn, context, this.$$throttledDigest.bind(this)); | |
| 129 | 134 | }; | |
| 130 | 135 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -340,5 +340,42 @@ describe('angular-meteor.core', function() { | |||
| 340 | 340 | scope.applyMethod('method', ['foo', 'bar'], angular.noop); | |
| 341 | 341 | }); | |
| 342 | 342 | }); | |
| 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 | + }); | ||
| 343 | 380 | }); | |
| 344 | 381 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments