PolymerElements / iron-pages

Simple content switcher
https://www.webcomponents.org/element/PolymerElements/iron-pages
48 stars 19 forks source link

Attached Method Calling on iron pages? #47

Closed nigeltiany closed 4 years ago

nigeltiany commented 8 years ago

What would be a better way to recalculate bindings when a page moves from being unselected to selected? Is an iron-page supposed to be attached when selected and dettached otherwise? That way a polymer component that is an iron page can have the attached property as a function that can be used to recalculate data bindings?

Here is my code

...
    <div>[[active]]</div>
</template
<script>
        Polymer({
            is: 'control-panel',
            properties: {
                active: {
                    type: String
                }
            },
            attached: function () {
                console.log('attached');
              this.active = this.activeAccount();
            },
            dettached: function () {
                console.log('dettached');
            },
           activeAccount: function(){
                //gets value by key from iron local storage
           }
           });
</script>
<iron-pages selected="[[view]]" attr-for-selected="name" role="main">
        <control-panel id="panel" name="panel"></control-panel>
        <choose-account name="accountSelect"></choose-account>
</iron-pages>
43081j commented 8 years ago

Do you mean something like the selectedAttribute?

<iron-pages selected-attribute="active" ...> will mean your boolean property, active, is set true/false when the page is active or not. Then in your observer of said property, update internal state if active === true.

nigeltiany commented 8 years ago

What i meant was life cycle callbacks. Methods that can called when an iron page is currently active, moves from being active or being viewed to hidden or inactive and any other callbacks necessary.

43081j commented 8 years ago

Isn't this exactly what I just said?

In the code snippet I posted above, you would have an observer on active. You say you want some kind of callback when the page moves from active to inactive, this is it. An observer on the selected attribute, which in my example is active.

attached/detached of course won't fire, it has already been attached. iron-pages will simply hide it. So how do you know it has hidden or unhidden? Again, an observer on the attribute specified in selectedAttribute.