feat: delete exceed gowitharg shit.

This commit is contained in:
Andrey Parhomenko 2024-07-23 17:41:31 +05:00
parent 94ccb0b724
commit 66c70d5b31
3 changed files with 18 additions and 17 deletions

View file

@ -161,7 +161,7 @@ func (compo *CommandCompo) Serve(c Context) {
// Closing current widget // Closing current widget
cmdUpdates.Close() cmdUpdates.Close()
// And running the other one. // And running the other one.
cmdUpdates, _ = c.runWidget(cmd.Widget, cmd.WidgetArg) cmdUpdates, _ = c.WithArg(cmd.WidgetArg).RunWidget(cmd.Widget)
} }
continue continue
} }

View file

@ -220,7 +220,7 @@ func (c Context) ReadFile(fileID FileID) ([]byte, string, error) {
return bts, pth, nil return bts, pth, nil
} }
func (c Context) runCompo(compo Component, arg any) (*UpdateChan, error) { func (c Context) RunCompo(compo Component) (*UpdateChan, error) {
if compo == nil { if compo == nil {
return nil, nil return nil, nil
} }
@ -235,8 +235,7 @@ func (c Context) runCompo(compo Component, arg any) (*UpdateChan, error) {
updates := NewUpdateChan() updates := NewUpdateChan()
go func() { go func() {
compo.Serve( compo.Serve(
c.WithInput(updates). c.WithInput(updates),
WithArg(arg),
) )
// To let widgets finish themselves before // To let widgets finish themselves before
// the channel is closed and close it by themselves. // the channel is closed and close it by themselves.
@ -246,20 +245,20 @@ func (c Context) runCompo(compo Component, arg any) (*UpdateChan, error) {
} }
// Run widget in background returning the new input channel for it. // Run widget in background returning the new input channel for it.
func (c Context) runWidget(widget Widget, arg any) (*UpdateChan, error) { func (c Context) RunWidget(widget Widget) (*UpdateChan, error) {
var err error var err error
if widget == nil { if widget == nil {
return nil, EmptyWidgetErr return nil, EmptyWidgetErr
} }
compos := widget.Render(c.WithArg(arg)) compos := widget.Render(c)
// Leave if changed path or components are empty. // Leave if changed path or components are empty.
if compos == nil { if compos == nil {
return nil, EmptyCompoErr return nil, EmptyCompoErr
} }
chns := make([]*UpdateChan, len(compos)) chns := make([]*UpdateChan, len(compos))
for i, compo := range compos { for i, compo := range compos {
chns[i], err = c.runCompo(compo, arg) chns[i], err = c.RunCompo(compo)
if err != nil { if err != nil {
for _, chn := range chns { for _, chn := range chns {
chn.Close() chn.Close()
@ -299,14 +298,16 @@ func (c Context) runWidget(widget Widget, arg any) (*UpdateChan, error) {
return ret, nil return ret, nil
} }
// Simple go without an argument for context. func (c Context) GoRet(pth Widget) WidgetGo {
func (c Context) Go(pth Widget) error { return WidgetGo{
return c.GoWithArg(pth, nil) Path: pth,
Arg: c.Arg(),
}
} }
// Go to the specified widget with the // Go to the specified widget
// specificed argument. // using context values.
func (c Context) GoWithArg(pth Widget, arg any) error { func (c Context) Go(pth Widget) error {
var err error var err error
if pth == nil { if pth == nil {
c.session.pathHistory = []Widget{} c.session.pathHistory = []Widget{}
@ -316,7 +317,7 @@ func (c Context) GoWithArg(pth Widget, arg any) error {
var back bool var back bool
if pth == Back { if pth == Back {
if len(c.session.pathHistory) < 2 { if len(c.session.pathHistory) < 2 {
return c.GoWithArg(nil, arg) return c.Go(nil)
} }
pth = c.session.pathHistory[len(c.session.pathHistory)-2] pth = c.session.pathHistory[len(c.session.pathHistory)-2]
c.session.pathHistory = c.session.pathHistory =
@ -332,7 +333,7 @@ func (c Context) GoWithArg(pth Widget, arg any) error {
c.session.skippedUpdates.Close() c.session.skippedUpdates.Close()
// Running the new one. // Running the new one.
c.session.skippedUpdates, err = c.runWidget(pth, arg) c.session.skippedUpdates, err = c.RunWidget(pth)
if err != nil { if err != nil {
return err return err
} }

4
go.go
View file

@ -14,8 +14,8 @@ type WidgetGo struct {
Arg any Arg any
} }
func (sc WidgetGo) Act(c Context) { func (w WidgetGo) Act(c Context) {
c.GoWithArg(sc.Path, sc.Arg) c.WithArg(w.Arg).Go(w.Path)
} }
// Implementing the Server interface. // Implementing the Server interface.