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);