From 03f8425d808f3c82b3cd3dca76e8e18b5983a379 Mon Sep 17 00:00:00 2001 From: Artem Chivchalov Date: Tue, 30 Sep 2014 11:32:40 +0300 Subject: [PATCH] Flag filters with `$stateful=true` for compatibility reasons with angular-1.3.0-rc.3 Closes #68 --- README.md | 2 +- example/index.html | 6 +++--- karma-angular-1.3.conf.js | 8 ++++---- src/route-segment.js | 30 ++++++++++++++++++++---------- test/unit/route-segment.spec.js | 16 ++++++++++++++++ 5 files changed, 44 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 642b664..c122766 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Or use this CDN link (thanks to [cdnjs.com](http://cdnjs.com)): ``` -Tested with AngularJS 1.1.5, 1.2.21 and 1.3.0-beta.17. +Tested with AngularJS 1.1.5, 1.2.21 and 1.3.0-rc.3. Overview -------- diff --git a/example/index.html b/example/index.html index 32462fa..c7223c1 100644 --- a/example/index.html +++ b/example/index.html @@ -39,9 +39,9 @@ - - - + + + diff --git a/karma-angular-1.3.conf.js b/karma-angular-1.3.conf.js index 7c3241d..cef4a83 100644 --- a/karma-angular-1.3.conf.js +++ b/karma-angular-1.3.conf.js @@ -8,10 +8,10 @@ module.exports = function(config) { files: [ 'test/lib/jquery.min.js', 'test/lib/helpers.js', - 'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.js', - 'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular-route.js', - 'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular-animate.js', - 'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular-mocks.js', + 'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular.js', + 'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular-route.js', + 'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular-animate.js', + 'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular-mocks.js', 'src/**/*.js', 'test/unit/**/*.js' ], diff --git a/src/route-segment.js b/src/route-segment.js index 94411c5..239974a 100644 --- a/src/route-segment.js +++ b/src/route-segment.js @@ -492,9 +492,11 @@ mod.provider( '$routeSegment', * */ mod.filter('routeSegmentUrl', ['$routeSegment', function($routeSegment) { - return function(segmentName, params) { + var filter = function(segmentName, params) { return $routeSegment.getSegmentUrl(segmentName, params); - } + }; + filter.$stateful = true; + return filter; }]); /** @@ -502,9 +504,11 @@ mod.filter('routeSegmentUrl', ['$routeSegment', function($routeSegment) { *
  • */ mod.filter('routeSegmentEqualsTo', ['$routeSegment', function($routeSegment) { - return function(value) { + var filter = function(value) { return $routeSegment.name == value; - } + }; + filter.$stateful = true; + return filter; }]); /** @@ -512,9 +516,11 @@ mod.filter('routeSegmentEqualsTo', ['$routeSegment', function($routeSegment) { *
  • */ mod.filter('routeSegmentStartsWith', ['$routeSegment', function($routeSegment) { - return function(value) { + var filter = function(value) { return $routeSegment.startsWith(value); - } + }; + filter.$stateful = true; + return filter; }]); /** @@ -522,9 +528,11 @@ mod.filter('routeSegmentStartsWith', ['$routeSegment', function($routeSegment) { *
  • */ mod.filter('routeSegmentContains', ['$routeSegment', function($routeSegment) { - return function(value) { + var filter = function(value) { return $routeSegment.contains(value); - } + }; + filter.$stateful = true; + return filter; }]); /** @@ -532,9 +540,11 @@ mod.filter('routeSegmentContains', ['$routeSegment', function($routeSegment) { *
  • */ mod.filter('routeSegmentParam', ['$routeSegment', function($routeSegment) { - return function(value) { + var filter = function(value) { return $routeSegment.$routeParams[value]; - } + }; + filter.$stateful = true; + return filter; }]); diff --git a/test/unit/route-segment.spec.js b/test/unit/route-segment.spec.js index 99f802c..cb6a028 100644 --- a/test/unit/route-segment.spec.js +++ b/test/unit/route-segment.spec.js @@ -985,5 +985,21 @@ describe('route segment', function() { $routeSegment.$routeParams.qux = 'quux'; expect($filter('routeSegmentParam')('qux')).toBe('quux'); })) + + it('should expect the filters to be stateful and not cached', inject(function($compile, $routeSegment, $rootScope) { + var elm = $('
    {{"qux" | routeSegmentParam}}
    '), + scope = $rootScope.$new(); + + $routeSegment.$routeParams.qux = 'quux'; + $compile(elm)(scope); + scope.$apply(); + + expect(elm.text()).toBe('quux'); + + $routeSegment.$routeParams.qux = 'changed'; + scope.$apply(); + + expect(elm.text()).toBe('changed'); + })) }) }) \ No newline at end of file