execute server side once after polymer component has been initialized (afte

No hei!

I have been facing this question in my application. I have a PolymerTemplate in which I want to perform some operations on the client side. My problem is that even if I override the onAttach method, when the server runs onAttach(), polymer has not even finished with ready() or connectedCallback() callbacks. Is it possible to defer my server code to a point when the polymer component is already set up?

In the onAttach() server code I update a client side property, so polymer runs the observer function immediately, however, there are some other initializations necessary in the component.

for clarity, my server code:

public class MyComponent extends PolymerTemplate<MyComponent.Model> {

    public interface  Model extends TemplateModel {
        void setOptions(String options);
    }

    @Override
    protected void onAttach(AttachEvent attachEvent) {
	  // should run this after client's connectedCallback()
      getModel().setOptions(...);
    }

}

client:

// imports omitted

class MyComponent extends PolymerElement {
   
   // ...
   
    static get template() {
        return html `
      // omitted 
    `;
    }


    static get properties() {
        return {
            options: {
               //....
                observer: 'setOptions'
            }
        };
    }

    setOptions(options) {
        // ... code that should be run at a later time
    }

    connectedCallback() {
         // this code should be run BEFORE the server updates properties and polymer runs setOptions
      }
      

}

window.customElements.define(MyComponent.is, MyComponent);

You could call the server from the template, something like this:

connectedCallback() {
    doStuff();
    this.$server.connectedCallback();
}   

and on the server

@ClientCallable
public void connectedCallback() {
    // Do stuff after the client connectedCallback has run here
}

Erik Lumme:
You could call the server from the template, something like this:

connectedCallback() {
    doStuff();
    this.$server.connectedCallback();
}   

and on the server

@ClientCallable
public void connectedCallback() {
    // Do stuff after the client connectedCallback has run here
}

thanks!