2 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9 <link rel=
"import" href=
"emitter.html">
13 var MoreRouting
= scope
.MoreRouting
= scope
.MoreRouting
|| {};
14 MoreRouting
.Params
= Params
;
17 * A collection of route parameters and their values, with nofications.
19 * Params prefixed by `__` are reserved.
21 * @param {!Array<string>} params The keys of the params being managed.
22 * @param {Params=} parent A parent route's params to inherit.
25 function Params(params
, parent
) {
26 var model
= Object
.create(parent
|| Params
.prototype);
27 // We have a different set of listeners at every level of the hierarchy.
28 Object
.defineProperty(model
, '__listeners', {value
: []});
30 // We keep all state enclosed within this closure so that inheritance stays
31 // relatively straightfoward.
33 _compile(model
, params
, state
);
37 Params
.prototype = Object
.create(MoreRouting
.Emitter
);
41 function _compile(model
, params
, state
) {
42 params
.forEach(function(param
) {
43 Object
.defineProperty(model
, param
, {
47 set: function(value
) {
48 if (state
[param
] === value
) return;
50 model
.__notify(param
, value
);