Add stateful resource navigation
This commit is contained in:
parent
adbd790c6f
commit
97dc090619
@ -36,20 +36,24 @@ type MenuResource struct {
|
|||||||
funcFunc FuncForFunc
|
funcFunc FuncForFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewMenuResource creates a new MenuResource instance.
|
||||||
func NewMenuResource() *MenuResource {
|
func NewMenuResource() *MenuResource {
|
||||||
return &MenuResource{}
|
return &MenuResource{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithCodeGetter sets the code symbol resolver method.
|
||||||
func(m *MenuResource) WithCodeGetter(codeGetter CodeFunc) *MenuResource {
|
func(m *MenuResource) WithCodeGetter(codeGetter CodeFunc) *MenuResource {
|
||||||
m.codeFunc = codeGetter
|
m.codeFunc = codeGetter
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithEntryGetter sets the content symbol resolver getter method.
|
||||||
func(m *MenuResource) WithEntryFuncGetter(entryFuncGetter FuncForFunc) *MenuResource {
|
func(m *MenuResource) WithEntryFuncGetter(entryFuncGetter FuncForFunc) *MenuResource {
|
||||||
m.funcFunc = entryFuncGetter
|
m.funcFunc = entryFuncGetter
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithTemplateGetter sets the template symbol resolver method.
|
||||||
func(m *MenuResource) WithTemplateGetter(templateGetter TemplateFunc) *MenuResource {
|
func(m *MenuResource) WithTemplateGetter(templateGetter TemplateFunc) *MenuResource {
|
||||||
m.templateFunc = templateGetter
|
m.templateFunc = templateGetter
|
||||||
return m
|
return m
|
||||||
|
29
go/resource/state.go
Normal file
29
go/resource/state.go
Normal file
@ -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
|
||||||
|
}
|
14
go/resource/state_test.go
Normal file
14
go/resource/state_test.go
Normal file
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user