Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components / more-routing / params.html
blob71b3d53a619bd46d6cb810162feefc18f93e0e67
1 <!--
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
8 -->
9 <link rel="import" href="emitter.html">
11 <script>
12 (function(scope) {
13 var MoreRouting = scope.MoreRouting = scope.MoreRouting || {};
14 MoreRouting.Params = Params;
16 /**
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.
23 * @return {Params}
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.
32 var state = {};
33 _compile(model, params, state);
35 return model;
37 Params.prototype = Object.create(MoreRouting.Emitter);
39 // Utility
41 function _compile(model, params, state) {
42 params.forEach(function(param) {
43 Object.defineProperty(model, param, {
44 get: function() {
45 return state[param];
47 set: function(value) {
48 if (state[param] === value) return;
49 state[param] = value;
50 model.__notify(param, value);
52 });
53 });
56 })(window);
57 </script>