glimmerjs/glimmer-component

Implement lifecycle hooks

tomdale opened this issue · 5 comments

  • didInsertElement (no this.element yet due to Glimmer bug)
  • didRender
  • didUpdate
  • willDestroy

@tomdale how about a didReceiveAttrs? Where the component has received the attrs, but has not yet rendered?

locks commented

@habdelra those are likely to come out of an RFC

@tomdale For my purposes I need a hook for after the DOM has been updated (we were calling this didRender from the Monegraph "proto standalone-glimmer" days.

My use case is that I'm using a <video> element that gets it source from a tracked property. When the source changes I need to tell the video element to load() using the HTML5 media API.

Looking at what you have above, it looks like you are proposing a didRender hook, which would suit my needs perfectly. However, in the currently existing didUpdate() hook, this comment appears, https://github.com/glimmerjs/glimmer-component/blob/master/src/component.ts#L189, which seems to indicate that didUpdate() is invoked after the component has rerendered itself. But when I actually try it out, I see that that is definitely not the case. Is the comment just incorrect?

Here's a simple little glimmerjs project demonstrating this: https://github.com/habdelra/glimmerjs-didUpdate-hook


EDIT: I actually logged this issue as: #51

I would also need some kind of didReceiveAttrs

This repo has been merged with glimmerjs/glimmer.js (into a monorepo setup). I am not sure if this issue is still applicable, but if you could confirm it is still an ongoing concern and open it over there that would be very helpful.

Sorry for the noise, but thank you for your help!