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