Skip to content

Commit

Permalink
Flag filters with $stateful=true for compatibility reasons with ang…
Browse files Browse the repository at this point in the history
…ular-1.3.0-rc.3

Closes #68
  • Loading branch information
artch committed Sep 30, 2014
1 parent fa5388e commit 03f8425
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Or use this CDN link (thanks to [cdnjs.com](http://cdnjs.com)):
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-route-segment/1.3.0/angular-route-segment.min.js"></script>
```

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
--------
Expand Down
6 changes: 3 additions & 3 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
</div>


<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular-route.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular-animate.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular-route.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular-animate.js"></script>
<script src="../build/angular-route-segment.min.js"></script>
<script src="app.js"></script>

Expand Down
8 changes: 4 additions & 4 deletions karma-angular-1.3.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
],
Expand Down
30 changes: 20 additions & 10 deletions src/route-segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,49 +492,59 @@ mod.provider( '$routeSegment',
* <a ng-href="{{ 'index.list.itemInfo' | routeSegmentUrl: {id: 123} }}">
*/
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;
}]);

/**
* Usage:
* <li ng-class="{active: ('index.list' | routeSegmentEqualsTo)}">
*/
mod.filter('routeSegmentEqualsTo', ['$routeSegment', function($routeSegment) {
return function(value) {
var filter = function(value) {
return $routeSegment.name == value;
}
};
filter.$stateful = true;
return filter;
}]);

/**
* Usage:
* <li ng-class="{active: ('section1' | routeSegmentStartsWith)}">
*/
mod.filter('routeSegmentStartsWith', ['$routeSegment', function($routeSegment) {
return function(value) {
var filter = function(value) {
return $routeSegment.startsWith(value);
}
};
filter.$stateful = true;
return filter;
}]);

/**
* Usage:
* <li ng-class="{active: ('itemInfo' | routeSegmentContains)}">
*/
mod.filter('routeSegmentContains', ['$routeSegment', function($routeSegment) {
return function(value) {
var filter = function(value) {
return $routeSegment.contains(value);
}
};
filter.$stateful = true;
return filter;
}]);

/**
* Usage:
* <li ng-class="{active: ('index.list.itemInfo' | routeSegmentEqualsTo) && ('id' | routeSegmentParam) == 123}">
*/
mod.filter('routeSegmentParam', ['$routeSegment', function($routeSegment) {
return function(value) {
var filter = function(value) {
return $routeSegment.$routeParams[value];
}
};
filter.$stateful = true;
return filter;
}]);


Expand Down
16 changes: 16 additions & 0 deletions test/unit/route-segment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<div>{{"qux" | routeSegmentParam}}</div>'),
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');
}))
})
})

0 comments on commit 03f8425

Please sign in to comment.