From 742e09e17c741b9dc5a3cc9a59b429cb545b73df Mon Sep 17 00:00:00 2001 From: Kevin Miller Date: Thu, 11 Apr 2024 10:19:53 -0500 Subject: [PATCH] Ensure init is run before updating with WindowSizeMsg --- navstack/model.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/navstack/model.go b/navstack/model.go index 6317fed..faa1829 100644 --- a/navstack/model.go +++ b/navstack/model.go @@ -59,12 +59,14 @@ func (m *Model) Push(item NavigationItem) tea.Cmd { } } + initCmd := item.Init() + wmsg := m.window.GetWindowSizeMsg() - nim, cmd := item.Model.Update(wmsg) + nim, winCmd := item.Model.Update(wmsg) item.Model = nim m.stack = append(m.stack, item) - return tea.Batch(cmd, item.Init()) + return tea.Sequence(initCmd, winCmd) } // Pop removes the top most navigation item from the stack. @@ -87,12 +89,11 @@ func (m *Model) Pop() tea.Cmd { return tea.Quit } - cmds := []tea.Cmd{} - nim, cmd := top.Model.Update(m.window.GetWindowSizeMsg()) + initCmd := top.Init() + nim, winCmd := top.Model.Update(m.window.GetWindowSizeMsg()) top.Model = nim - cmds = append(cmds, cmd, top.Init()) - return tea.Batch(cmds...) + return tea.Sequence(winCmd, initCmd) } // Clear pops all the items from the stack.