ApplicationImpl cleanup, part 1:
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components-chromium / more-routing / params-extracted.js
blob9a9a1ee3d3cf494f19843f91a7dbdeb4c1e0b6d5
2 (function(scope) {
3 var MoreRouting = scope.MoreRouting = scope.MoreRouting || {};
4 MoreRouting.Params = Params;
6 /**
7 * A collection of route parameters and their values, with nofications.
9 * Params prefixed by `__` are reserved.
11 * @param {!Array<string>} params The keys of the params being managed.
12 * @param {Params=} parent A parent route's params to inherit.
13 * @return {Params}
15 function Params(params, parent) {
16 var model = Object.create(parent || Params.prototype);
17 // We have a different set of listeners at every level of the hierarchy.
18 Object.defineProperty(model, '__listeners', {value: []});
20 // We keep all state enclosed within this closure so that inheritance stays
21 // relatively straightfoward.
22 var state = {};
23 _compile(model, params, state);
25 return model;
27 Params.prototype = Object.create(MoreRouting.Emitter);
29 // Utility
31 function _compile(model, params, state) {
32 params.forEach(function(param) {
33 Object.defineProperty(model, param, {
34 get: function() {
35 return state[param];
37 set: function(value) {
38 if (state[param] === value) return;
39 state[param] = value;
40 model.__notify(param, value);
42 });
43 });
46 })(window);