Giter Site home page Giter Site logo

Comments (7)

xcambar avatar xcambar commented on September 24, 2024 4

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

from glimmer-experimental.

lifeart avatar lifeart commented on September 24, 2024 1

@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

from glimmer-experimental.

lifeart avatar lifeart commented on September 24, 2024 1

@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}}

from glimmer-experimental.

argarcia-ottersoft avatar argarcia-ottersoft commented on September 24, 2024

any update on this? any workarounds?

from glimmer-experimental.

argarcia-ottersoft avatar argarcia-ottersoft commented on September 24, 2024

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

from glimmer-experimental.

argarcia-ottersoft avatar argarcia-ottersoft commented on September 24, 2024

@lifeart, any reason why a nested component in App's {{#if this.isAlive}}<ChildComponent />{{/if}} would not fire the willDestroy() hook after setting the App's isAlive property to false? The <ChildComponent /> does successfully get removed from the screen

from glimmer-experimental.

argarcia-ottersoft avatar argarcia-ottersoft commented on September 24, 2024

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.

from glimmer-experimental.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.