Skip to content

Commit 50cef21

Browse files
fix(StateBuilder): Made ownParams isolate params to those owned by the state, even URL params.
1 parent 0550a15 commit 50cef21

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/params/paramSet.ts

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export default class ParamSet {
99
return inherit(inherit(this, { $$parent: () => this }), params);
1010
}
1111

12+
$$own() {
13+
return extend(new ParamSet(), this);
14+
}
15+
1216
$$keys() {
1317
var keys = [], chain = [], parent = this,
1418
ignore = objectKeys(ParamSet.prototype);

src/state/stateBuilder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default function StateBuilder(root, matcher, $urlMatcherFactoryProvider)
3838

3939
// Own parameters for this state. state.url.params is already built at this point. Create and add non-url params
4040
ownParams: function(state) {
41-
var params = state.url && state.url.params || new ParamSet();
41+
var params = state.url && state.url.params.$$own() || new ParamSet();
4242
forEach(state.params || {}, function(config, id) {
4343
if (!params[id]) params[id] = new Param(id, null, config, "config");
4444
});

test/urlMatcherFactorySpec.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
var module = angular.mock.module;
22
var uiRouter = require("ui-router");
3-
var provide, UrlMatcher, ParamSet, Param;
3+
var ParamSet = uiRouter.params.ParamSet;
4+
var Param = uiRouter.params.Param;
5+
var provide, UrlMatcher;
46

57
beforeEach(function() {
68
var app = angular.module('ui.router.router.test', function () { });
79
app.config(function ($urlMatcherFactoryProvider) {
810
provider = $urlMatcherFactoryProvider;
911
UrlMatcher = provider.UrlMatcher;
1012
ParamSet = provider.ParamSet;
11-
Param = provider.Param;
13+
//Param = provider.Param;
1214
});
1315
});
1416

@@ -503,7 +505,7 @@ describe("urlMatcherFactory", function () {
503505
expect($umf.compile('/hello/world').exec('/heLLo/WORLD')).toBeNull();
504506
});
505507

506-
it("should handle case insensistive URL", function () {
508+
it("should handle case insensitive URL", function () {
507509
$umf.caseInsensitive(true);
508510
expect($umf.compile('/hello/world').exec('/heLLo/WORLD')).toEqual({});
509511
});
@@ -882,6 +884,22 @@ describe("urlMatcherFactory", function () {
882884
});
883885
});
884886

887+
describe(".$$own", function() {
888+
it("should return a new ParamSet which does not expose ancestor Params (only exposes own Params)", function() {
889+
var grandparent = new ParamSet({ grandparent: params.grandparent });
890+
var parent = grandparent.$$new({ parent: params.parent });
891+
var child = parent.$$new({ child: params.child });
892+
893+
expect(child.grandparent).toBe(params.grandparent);
894+
var own = child.$$own();
895+
896+
expect(own.$$keys()).toEqual(["child"]);
897+
expect(own.child).toBe(params.child);
898+
expect(own.parent).toBeUndefined();
899+
expect(own.grandparent).toBeUndefined();
900+
});
901+
});
902+
885903
describe(".$$keys", function() {
886904
it("should return keys for current param set", function() {
887905
var ps = new ParamSet();

0 commit comments

Comments
 (0)