-
Notifications
You must be signed in to change notification settings - Fork 26
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
Way to access rendered component instance #45
Comments
I'd like to second this statement, especially as detailed here: glimmerjs/glimmer.js#235 (comment) The absence of such API forces implementors to use unpleasing (to say the least) workarounds ;) |
any update on this? any workarounds? |
@argarcia-ottersoft workaround exists, you could pass service into component and inside it's contructor assign this to some service property. class App extends Component {
@service app;
constructor() {
super(...arguments);
this.app.setComponent(this);
}
}
class MyService {
component = null;
setComponent(value) {
this.component = value;
}
}
const appService = new MyService();
await renderComponent(App, { services: { app: appService } } )
appService.component === App instance |
awesome! thanks @lifeart follow up question, is there any way to properly unload the component? I'm trying to do cleanup in web components disconnectedCallback method |
@argarcia-ottersoft there is issue for it - #123 But, I could assume that minimal unload logic should be like: // app's hbs class App extends Component {
@tracked
isAlive = true;
async destroy() {
this.isAlive = false;
await new Promise((resolve) => setTimeout(resolve)); // need to wait for rerender
// nested components should be destroyed here and all you need is cleanup services used for component
}
} {{#if this.isAlive}}
... app logic
{{/if}} |
@lifeart, any reason why a nested component in App's |
never mind, it was an error on my end. An exception was being thrown while looping through scheduledDestructors cause of a version mismatch of @glimmer/destroyable. glimmer-class-based-modifier depended on version 0.77.3 while glimmer.js depended on 0.77.6 so updating glimmer-class-based-modifier to 0.77.6 fixed issue. |
wor web components usage and for inegration with different external APIS, it's will be grate to have
official
ability to access rendered glimmer app.following examples:
is it possible to return component instance as resolved promise argument?
or
opts = { connected(instance) {} }
The text was updated successfully, but these errors were encountered: