How to notify page transitions using iron pages
I am playing around with The Polymer Starter Kit creating a simple application with multiple pages. I would like one of the pages to display a list of items that it downloads from the server. The problem is that this list should only load when the page is visible / navigated to. How should I notify the "lazy list" to start loading data?
<iron-pages attr-for-selected="data-route" selected="{{route}}">
<section data-route="some-page">
<paper-material>
<lazy-list></lazy-list>
</paper-material>
</section>
<section data-route="another page">
<paper-material elevation="1">
...
</paper-material>
</section>
</iron-pages>
source to share
Or can you just watch route
while route === "some-page"
submitting an update request to <lazy-list>
?
<dom-module id="my-app">
<template>
...
<iron-pages attr-for-selected="data-route" selected="{{route}}">
<section data-route="some-page">
<paper-material>
<lazy-list id="list"></lazy-list>
</paper-material>
</section>
<section data-route="another page">
<paper-material elevation="1">
...
</paper-material>
</section>
</iron-pages>
...
</template>
<script>
Polymer({
is: "my-app",
properties: {
route: {
type: String,
observer: "routeChanged"
},
...
},
...
routeChanged: function (newval,oldval) {
if (newval === "some-page") {
this.$.list.refreshList();
}
},
...
});
</script>
</dom-module>
No new item required.
source to share
Not sure if this is the best solution, but I just created a new "page" element that wraps this section. This element listens for attribute changes and loads the list when iron is added to the class name.
<dom-module id="some-page">
<style>
</style>
<template>
<paper-material>
<lazy-list id="list"></lazy-list>
</paper-material>
</template>
<script>
(function() {
Polymer({
is: 'some-page',
ready : function(){
},
attributeChanged : function(name, type){
if(this.getAttribute('class').includes('iron-selected')){
this.$.list.refreshList();
}
}
});
})();
</script>
</dom-module>
source to share