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
cmdUpdates.Close()
// And running the other one.
cmdUpdates, _ = c.runWidget(cmd.Widget, cmd.WidgetArg)
cmdUpdates, _ = c.WithArg(cmd.WidgetArg).RunWidget(cmd.Widget)
}
continue
}

View file

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

4
go.go
View file

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