| OLD | NEW |
| (Empty) |
| 1 'use strict'; | |
| 2 | |
| 3 Polymer({ | |
| 4 is: 'carbon-route-converter', | |
| 5 | |
| 6 properties: { | |
| 7 /** | |
| 8 * A model representing the deserialized path through the route tree, as | |
| 9 * well as the current queryParams. | |
| 10 * | |
| 11 * A route object is the kernel of the routing system. It is intended to | |
| 12 * be fed into consuming elements such as `carbon-route`. | |
| 13 * | |
| 14 * @type {?Object} | |
| 15 */ | |
| 16 route: { | |
| 17 type: Object, | |
| 18 value: null, | |
| 19 notify: true | |
| 20 }, | |
| 21 | |
| 22 /** | |
| 23 * A set of key/value pairs that are universally accessible to branches of | |
| 24 * the route tree. | |
| 25 * | |
| 26 * @type {?Object} | |
| 27 */ | |
| 28 queryParams: { | |
| 29 type: Object, | |
| 30 value: null, | |
| 31 notify: true | |
| 32 }, | |
| 33 | |
| 34 /** | |
| 35 * The serialized path through the route tree. This corresponds to the | |
| 36 * `window.location.pathname` value, and will update to reflect changes | |
| 37 * to that value. | |
| 38 */ | |
| 39 path: { | |
| 40 type: String, | |
| 41 notify: true, | |
| 42 value: '' | |
| 43 } | |
| 44 }, | |
| 45 | |
| 46 observers: [ | |
| 47 '_locationChanged(path, queryParams)', | |
| 48 '_routeChanged(route.prefix, route.path)', | |
| 49 '_routeQueryParamsChanged(route.__queryParams)' | |
| 50 ], | |
| 51 | |
| 52 created: function() { | |
| 53 this.linkPaths('route.__queryParams', 'queryParams'); | |
| 54 this.linkPaths('queryParams', 'route.__queryParams'); | |
| 55 }, | |
| 56 | |
| 57 /** | |
| 58 * Handler called when the path or queryParams change. | |
| 59 * | |
| 60 * @param {!string} path The serialized path through the route tree. | |
| 61 * @param {Object} queryParams A set of key/value pairs that are | |
| 62 * universally accessible to branches of the route tree. | |
| 63 */ | |
| 64 _locationChanged: function(path, queryParams) { | |
| 65 this.route = { | |
| 66 prefix: '', | |
| 67 path: path, | |
| 68 __queryParams: queryParams | |
| 69 }; | |
| 70 }, | |
| 71 | |
| 72 /** | |
| 73 * Handler called when the route prefix and route path change. | |
| 74 * | |
| 75 * @param {!string} prefix The fragment of the pathname that precedes the | |
| 76 * path. | |
| 77 * @param {!string} path The serialized path through the route tree. | |
| 78 */ | |
| 79 _routeChanged: function(prefix, path) { | |
| 80 if (!this.route) { | |
| 81 return; | |
| 82 } | |
| 83 | |
| 84 this.path = prefix + path; | |
| 85 }, | |
| 86 | |
| 87 /** | |
| 88 * Handler called when the route queryParams change. | |
| 89 * | |
| 90 * @param {Object} queryParams A set of key/value pairs that are | |
| 91 * universally accessible to branches of the route tree. | |
| 92 */ | |
| 93 _routeQueryParamsChanged: function(queryParams) { | |
| 94 if (!this.route) { | |
| 95 return; | |
| 96 } | |
| 97 this.queryParams = queryParams; | |
| 98 } | |
| 99 }); | |
| OLD | NEW |