mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
feat: updated cache implementation and fixed bugs
This commit is contained in:
parent
17dbfa2b3b
commit
e71f33878e
7 changed files with 550 additions and 97 deletions
60
internal/cache/state.go
vendored
Normal file
60
internal/cache/state.go
vendored
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
package cache
|
||||
|
||||
type editorState interface{}
|
||||
type selecting struct{}
|
||||
type editting struct{}
|
||||
|
||||
type Editor struct {
|
||||
state editorState
|
||||
}
|
||||
|
||||
// transition between state
|
||||
|
||||
func NewEditor() Editor {
|
||||
return Editor{state: selecting{}}
|
||||
}
|
||||
|
||||
func (e *Editor) StartEditting() editting {
|
||||
e.state = editting{}
|
||||
return e.state.(editting)
|
||||
}
|
||||
|
||||
func (e *Editor) StopEditting() selecting {
|
||||
e.state = selecting{}
|
||||
return e.state.(selecting)
|
||||
}
|
||||
|
||||
func (s editting) FinishEditting(e *Editor) selecting {
|
||||
e.state = selecting{}
|
||||
return e.state.(selecting)
|
||||
}
|
||||
|
||||
func (e *Editor) GetState() editorState {
|
||||
return e.state
|
||||
}
|
||||
|
||||
func (e *Editor) GetStateString() string {
|
||||
switch e.state.(type) {
|
||||
case selecting:
|
||||
return "selecting"
|
||||
case editting:
|
||||
return "editting"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (e *Editor) IsEditting() bool {
|
||||
return e.GetStateString() == "editting"
|
||||
}
|
||||
|
||||
func (e *Editor) IsSelecting() bool {
|
||||
return e.GetStateString() == "selecting"
|
||||
}
|
||||
|
||||
func test() {
|
||||
editor := NewEditor()
|
||||
editting := editor.StartEditting()
|
||||
|
||||
// ...later on...
|
||||
editting.FinishEditting(&editor)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue