-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Routing satisfied in two different sub-pages #164
Comments
Ad the moment I am "solving" this by having a check in
And then:
But seriously... |
I have encountered this issue as well and maybe we can implement the solution in <iron-pages id="pageSelector" role="main" selected="[[page]]" attr-for-selected="name" fallback-selection="view404"
selected-attribute="route" selected-attribute-value="{{subRoute}}">
<my-gig
name="gig"
</my-gig>
<my-city
name="city"
</my-city>
</iron-pages> This is less code to write and fixes your issue. @bicknellr would you accept a pullrequest that implements the behavior described above? |
After discovering several issues with app-route, this being one of them I ended up implementing an alternative. I am not particularly promoting this here, but you can find it on my github account if interested ( Back when I was still using |
@TimvdLippe Are you proposing the behaviour purely so that you can save the one line:
...? How would it fix my issue in terms of stopping @akc42 I really do see the point of your module. However, I looked at Polymer 2, and I saw that they finally implemented atomic changes to multiple properties, making things easier. Since we will be transitioning Gigsnet to Polymer 2 sooner rather than later... I must admit I found app-route beautiful in theory, but painful in practice -- especially when writing a complex, large one-page application. |
@mercmobily Since |
Ah, I had totally missed it, good point!
…On 5 December 2016 at 19:51, Tim van der Lippe ***@***.***> wrote:
@mercmobily <https://github.com/mercmobily> Since selected-attribute is
only set on the currently selected item (in your case a page), this means
that when a page is not active, it's selected-attribute will be {}. When
a page is active, it will be subRoute
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#164 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACB7XtWYmwXdJG-sULhzwQow6qNH8meIks5rE_qkgaJpZM4LDk8Z>
.
|
Use Conditional templates instead of https://www.polymer-project.org/1.0/docs/devguide/templates#dom-if <template id="faq" is="dom-if" restamp>
<page-faq class="page" app="{{app}}"></page-faq>
</template>
<template id="feed" is="dom-if">
<page-feed class="page" app="{{app}}" route="{{route}}"></page-feed>
</template> _pageChanged: function(newPage, oldPage) {
if (!this.$[newPage]) {
newPage = '404';
}
if (oldPage) {
if (!this.$[oldPage]) {
oldPage = '404';
}
this.$$('page-' + oldPage).active = false;
this.$[oldPage].if = false;
}
this.$[newPage].if = true;
// Wait 1 tick for template to stamp.
this.async(function() {
this.$$('page-' + newPage).active = true;
// Load page import on demand. Show 404 page if fails. Disable async for after lazy loaded elements.
var resolvedPageUrl = this.resolveUrl('page-' + newPage + '.html');
this.importHref(resolvedPageUrl, null, this._showPage404, false);
});
},
_showPage404: function() {
this.page = '404';
} |
@JosefJezek OK OK it works but still... |
Actually, this was pretty much all user talk... what do Polymer developers think about this one? Will this be addressed in P2.0? |
This problem was driving absolutely bonkers. Every page had to constantly check if the first URL parameter was there because another page was simply being displayed. JosefJezek only really worked if I restamped everything all the time -- which also wasn't acceptable. The real problem is that passing So... I think I actually fixed. Elegantly. So in
One of the sub-pages
In
Basically, each page has its own Managing this is ridiculously simple. It's a property:
And then when
Note that only the page's own
I honestly think this is the neatest possible solution, and (unless the Polymer 2 routing solves this problem elegantly in the first place in some other way) it should become an established pattern, explained in the basic documentation. I hope this helps! Merc. |
@arthurevans Please check with the guys that what I wrote makes sense, and if it's worthwhile documenting this. I think it's a biggie, as I had endless problems with routing before this solution, and I think it's a very very common use case. |
Cancel that.
This is bad news, because it will mean that the sub-page's own What I ended up doing is a hack that cannot possibly be considered a pattern. This is the summary. The first half is identical to my previous comment, while the second half isn't. So in
One of the sub-pages
In
Basically, each page has its own Managing this is ridiculously simple. It's a property:
And then when
NOTE that I have a sentinel variable, as well as a lame deep-copy of the array that uses JSON's parse/stringify. There is also a need to reflect the changes back to the app's This code won't win any awards:
(The path function is called I hope this example will show the length I went through to get this to work.
This is limited to one parameter... and it really feels tailored for app-route. However, there is no easy way to make it "generic" and allow it to accept multiple parameters. |
@mercmobily multiple parameters would just pass an object with a field _createObject: function(subRoute, other) {
return {
subRoute: subRoute,
other: other
};
} |
Ah true. Always one step ahead @TimvdLippe :D I see your point. It's just one of those problems where you keep thinking "there's gonna HAVE TO be a better, easier solution"... |
@mercmobily I am using Conditional templates for security reason and low memory using. |
@TimvdLippe Is your fix using |
@jsilvermist Good question. I have not been able to work on it (it is a very easy change though), primarily because not a lot of PRs on PolymerElements are merged right now. Probably because they are working hybrid mode instead. I added it to my TODO-list so hopefully I can work on it soonTM. |
I'm confused, why did you implement this on |
@TimvdLippe I would love to have a simpler solution. The way I am dealing wit hit is working well, but it's a ridiculous solution. |
@jsilvermist Because @mercmobily This solution is I think the simplest you can come up with. It is DRY. |
@TimvdLippe Ah didn't realize the context, makes perfect sense now! Nice! |
The more I look at it, the more I like it.
They both work the same way: they have an observer on Other than that, PLEASE YES PLEASE apply this PR, it solves a huge problem with app-route right now... |
@TimvdLippe I just spent 2 hours fixing a problem with my "solution". Please tell me that there is some good news (see: your solution was committed) for this terrible problem that will affect any decently-sized app...! |
@mercmobily I suspect all PRs will be reconsidered once Polymer 2.0 has officially been released. So a little more patience right now I think? |
Ahhhhh that's what I feared. Oh well, my "solution" works well enough. It's just that I am about to release to production, and... let's be honest, it's not really a "solution"... whereas yours is. |
I tried applying the pull request that @TimvdLippe had, but it didn't work as expected. Is it certain that the solution works for the given original reported issue? |
@TimvdLippe Thank you so much for your work on this. I am in the process of migrating to P2, and refactoring. How far away do you think this PR is? PolymerElements/iron-selector#148 Please let us know! |
Still waiting for review, so I am not sure. You can rely on my fork with
the branch though, if you want to use it already.
Op do 14 dec. 2017 om 09:08 schreef Tony Mobily <[email protected]>:
… @TimvdLippe <https://github.com/timvdlippe> Thank you so much for your
work on this. I am in the process of migrating to P2, and refactoring. How
far away do you think this PR is? PolymerElements/iron-selector#148
<PolymerElements/iron-selector#148> Please let us
know!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#164 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFrDb-eZoKiQRC01cNrGeashd9TDqM-Yks5tANd0gaJpZM4LDk8Z>
.
|
A couple of questions:
Your example reads:
So... if
Am I missing something? The more I look at it, the more I think that there is a bit of an architectural issue, |
Ok, enough of this ridiculously long discussion. First of all @TimvdLippe solution won't work. You guys trying to patch component which has nothing to do with this issue. Story number two. Issue #148. This is where we (core devs actually, but ohh well my generosity..) completely forgot how and why Line 395 in 6b28803
Yes, updates should be ordered. Not just active and data which is solved (actually not) here #218, but also data and tail . In this pull request @cdata says 'LGTM', but it is not good at all. Core implementation of setProperties relies on "for .. in" which does not guarantee order of enumeration for object properties.
So, why @TimvdLippe solution won't work? Because what happens now is So what would be the fastest solution for now?PR? Not so fast usually. If you need it work right now @mercmobily, go create a patch component: <dom-module id="app-route-patch">
<template>
<slot id="slot"></slot>
</template>
<script>
class AppRoutePatch extends Polymer.Element {
static get is() {
return 'app-route-patch'
}
connectedCallback() {
super.connectedCallback();
//filter all app-routes, should be one really
const appRoutes = this.$.slot.assignedNodes().filter(node => {
return node.nodeType == Node.ELEMENT_NODE && node.nodeName.toUpperCase() == "APP-ROUTE";
});
//patch according to this https://github.com/PolymerElements/app-route/issues/164
appRoutes.forEach(appRoute => {
const superSetProperties = appRoute.setProperties;
appRoute.setProperties = function (propertyUpdates, isReadOnly) {
if (propertyUpdates.hasOwnProperty("data")) {
appRoute._setActive(false);
appRoute.set("data", propertyUpdates.data);
}
propertyUpdates.hasOwnProperty("tail") && appRoute.set("tail", propertyUpdates.tail);
appRoute._setActive(true);
}
})
}
}
window.customElements.define(AppRoutePatch.is, AppRoutePatch);
</script>
</dom-module> And use it like this: <app-route-patch>
<app-route
route="{{route}}"
pattern="[[rootPath]]:page"
data="{{routeData}}"
active="{{routeActive}}"
tail="{{routeTail}}"></app-route>
</app-route-patch> Full example: <app-route-patch>
<app-route
id="route"
route="{{route}}"
pattern="[[rootPath]]:page"
data="{{routeData}}"
active="{{routeActive}}"
tail="{{routeTail}}"></app-route>
</app-route-patch>
<iron-pages id="pageSelector" role="main" selected="[[page]]" attr-for-selected="name" fallback-selection="view404" selected-attribute="visible" >
<my-gig name="gig" parent-route-active="{{routeActive}}"></my-gig>
<my-city name="city" parent-route-active="{{routeActive}}"></my-city>
</iron-pages> Every page inherits from BasePage wich looks like this <dom-module id="base-page">
<script>
class BasePage extends Polymer.Element {
static get is() {
return 'base-page'
}
static get observers() {
return [
'_computeActive(parentRouteActive, visible)'
]
}
static get properties() {
return {
routeTail: {
type: Object,
notify: true
},
parentRouteActive: {
type: Boolean
},
visible: {
type: Boolean,
observer: "onVisibleChange"
},
active: {
type: Boolean
}
}
}
_computeActive(routeActive, visible) {
this.active = routeActive && visible
}
}
window.customElements.define(BasePage.is, BasePage);
</script>
</dom-module> |
I am a little lost... Isn't the new supa-dupa version of app-route supposed to make atomic changes to the data, so that there is only one notification for all changes? I really though that with P2 the whole "ordering nightmare" would be over? Second... what does your patching component do...? |
As I understand, technically it will be one update, but the way binding works is for every updated property |
My final workaround works like this:
Then in your program you'd go:
This is basically to 1) Provide each page its own subroute object to avoid overlaps 2) Allow pages to actually change SURELY this isn't a good way to go about it... but it's better than anything else I've tried. |
I have this in
my-app.html
:It's a fairly standard routing.
One of the sub-pages
my-gigs.html
, which is loaded dynamically (ala PSK) and contains:In
my-gig.html
, I want to be able to view a specific gig depending on the URL. So, I have:The trouble is that when I go to a different page in the application (say
/city/perth-au
, being displayed frommy-city.html
), the route above is active (!). It will have, asgigId
,perth-au
(which is totally wrong, since it's obviously NOT a valid ID).I am lost. Whenever I had problems before with routing, I would use the
active
flag to check if the route was actually active. In this problem, I have a problem because/city/perth-au
and/gig/445454545
will BOTH satisfy the routing inmy-gig.html
.What I am doing wrong...?
The text was updated successfully, but these errors were encountered: