From 27416e9976cf768f6b3c8316eebcbba990711e9d Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Fri, 10 Apr 2020 15:43:18 -0400 Subject: [PATCH] Add nil checks to CmdMap and SubMap functors --- tea.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tea.go b/tea.go index e71da98..132d7d8 100644 --- a/tea.go +++ b/tea.go @@ -9,7 +9,8 @@ import ( "github.com/muesli/termenv" ) -// Msg represents an action. It's used signal Update to update the UI. +// Msg represents an action and is usually the result of an IO operation. It's +// used to signal Update this model, and henceforth, the UI. type Msg interface{} // Model contains the updatable data for an application @@ -20,6 +21,9 @@ type Cmd func(Model) Msg // CmdMap applies a given model to a command func CmdMap(cmd Cmd, model Model) Cmd { + if cmd == nil { + return nil + } return func(_ Model) Msg { return cmd(model) } @@ -42,6 +46,9 @@ type Sub func(Model) Msg // SubMap applies a given model to a subscription func SubMap(sub Sub, model Model) Sub { + if sub == nil { + return nil + } return func(_ Model) Msg { return sub(model) }