opentui
opentui copied to clipboard
feat: improve lifecycle management
Fixes #248.
Changes
Core
- Adds new
exitSignalsoption to renderer, which specifies a list of signals that the renderer should destroy itself upon receiving.- The handlers are mounted when the renderer is created or resumed, and are unmounted when the renderer is suspended.
- The exit handler is now run on the
beforeExitevent. Theexitevent does not allow for more tasks to be added to the event loop, and thus theBun.sleep(200)call would be effectively ignored, preventing the captured logs from being dumped.
React
- Deduplicates repeated logic between the
createRootandrendermethods. - Exposes the renderer on the
rendermethods to make it easier to implement external lifecycle control.
Solid
- Exposes the renderer on the
rendermethods to make it easier to implement external lifecycle control. - Applies the changes from #270 to the
@opentui/solidpackage as well. This is helpful for lifecycle control because it inherently exposes therenderer(the user has to create one beforehand).- A
createRootmethod already exists in thesolid-jspackage, which could create some confusion. Should I rename it? Open to suggestions! - Also updated all
@opentui/solidexamples and README.md to reflect the new API.
- A
Thanks for looking into this. This makes sense. Only thing I need to work with this is the engine for the Timeline. We could just let the renderer have an engine getter (engine was just for the lack of better naming, can be renamed), which lazily creates an engine instance and attaches it to the renderer and the useTimeline hook can use renderer.engine instead of the global one. Then it should work. I don't think that is test covered currently I am afraid.
Also changed the exitHandler to run on beforeExit instead of exit. On exit, the capture dumping would not run because the runtime does not allow for more tasks to be scheduled on the event loop at that point. Using the beforeExit event fixes that problem!
Nice, I'll take it for a quick spin in the morning and check what I need to do for opencode, but this should be fine.
Sorry I've broken this
Sorry I've broken this
I'll take a look at it tomorrow, no worries!