go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

commit 97dc090619eddcccb8162f84d074c8656c1b051c
parent adbd790c6fe9bfb4fe3e5ec0ce8fdd089f64a775
Author: lash <dev@holbrook.no>
Date:   Sat,  8 Apr 2023 10:20:34 +0100

Add stateful resource navigation

Diffstat:
Mgo/resource/resource.go | 4++++
Ago/resource/state.go | 29+++++++++++++++++++++++++++++
Ago/resource/state_test.go | 14++++++++++++++
3 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/go/resource/resource.go b/go/resource/resource.go @@ -36,20 +36,24 @@ type MenuResource struct { funcFunc FuncForFunc } +// NewMenuResource creates a new MenuResource instance. func NewMenuResource() *MenuResource { return &MenuResource{} } +// WithCodeGetter sets the code symbol resolver method. func(m *MenuResource) WithCodeGetter(codeGetter CodeFunc) *MenuResource { m.codeFunc = codeGetter return m } +// WithEntryGetter sets the content symbol resolver getter method. func(m *MenuResource) WithEntryFuncGetter(entryFuncGetter FuncForFunc) *MenuResource { m.funcFunc = entryFuncGetter return m } +// WithTemplateGetter sets the template symbol resolver method. func(m *MenuResource) WithTemplateGetter(templateGetter TemplateFunc) *MenuResource { m.templateFunc = templateGetter return m diff --git a/go/resource/state.go b/go/resource/state.go @@ -0,0 +1,29 @@ +package resource + +import ( + "git.defalsify.org/festive/state" +) + +type StateResource struct { + Resource + st *state.State +} + +func ToStateResource(rs Resource) *StateResource { + return &StateResource{rs, nil} +} + +func NewStateResource(st *state.State) *StateResource { + return &StateResource { + NewMenuResource(), + st, + } +} + +func(s *StateResource) WithState(st *state.State) *StateResource { + if s.st != nil { + panic("state already set") + } + s.st = st + return s +} diff --git a/go/resource/state_test.go b/go/resource/state_test.go @@ -0,0 +1,14 @@ +package resource + +import ( + "testing" + + "git.defalsify.org/festive/state" +) + +func TestStateResourceInit(t *testing.T) { + st := state.NewState(0) + rs := NewMenuResource() + _ = ToStateResource(rs).WithState(&st) + _ = NewStateResource(&st) +}