bubbletea icon indicating copy to clipboard operation
bubbletea copied to clipboard

Handling tea.QuitMsg directly.

Open tbistr opened this issue 2 years ago • 1 comments

I want a nested model to handle child model's quitting. If the parent model and children implemented as a library, there is no way to detect quitting as far as I know.

If the parent is executable, we can use tea.WithFilter. If the children are included in its own library, we can use custom msg.

Is there any way to handle tea.QuitMsg? Why the parent model cann't catch tea.QuitMsg that issued by a child's tea.Quit?

I originaly had a question like belows, but I noticed about #472 and the prevent-quit example before I post.


I have created a model that has a nested structure. I want to transition from a parent model to a child model. The parent model passes a tea.Msg to parent.childModel.Update(msg) ,takes the returned model into its own struct and returns (ownself, returned cmd). As far as I understand, when the earlier model quited, the parent model also recieves tea.QuitMsg. So, It whould be able to determine which model finished with handling tea.QuitMsg and using some flags.

However, tea.QuitMsg doesn't appear in logs with fmt.Fprintln(f, reflect.TypeOf(msg)).

How to handle tea.QuitMsg of a child model? The child model is defined in another library, so I can't use custom msg.

tbistr avatar Aug 12 '23 19:08 tbistr

Something like preQuitMsg might be a good idea🤔?

tbistr avatar Aug 12 '23 19:08 tbistr

I'm not sure I understand this correctly, what prevents you from using a filter?

muesli avatar Mar 01 '24 17:03 muesli

So if I'm reading this correctly, the child's Cmd needs to be returned by the parent in order for a quitMsg to be properly processed. Conversely, if the child is returning a quitMsg and we don't want that to happen it can be filtered out via WithFilter.

If that doesn't answer your question, @tbistr, and we're totally missing something by all means please re-open this and let us know.

meowgorithm avatar Apr 17 '24 02:04 meowgorithm