Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nav): traverse callback should be referenced via pointer (#340) #343

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions xfs/nav/filter-glob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var _ = Describe("FilterGlob", Ordered, func() {
o.Store.Subscription = entry.subscription
o.Store.FilterDefs = filterDefs
o.Store.DoExtend = true
o.Callback = nav.LabelledTraverseCallback{
o.Callback = &nav.LabelledTraverseCallback{
Label: "test glob filter callback",
Fn: func(item *nav.TraverseItem) error {
GinkgoWriter.Printf(
Expand Down Expand Up @@ -216,7 +216,7 @@ var _ = Describe("FilterGlob", Ordered, func() {
o.Store.Subscription = entry.subscription
o.Store.FilterDefs = filterDefs
o.Store.DoExtend = true
o.Callback = nav.LabelledTraverseCallback{
o.Callback = &nav.LabelledTraverseCallback{
Label: "test glob filter callback",
Fn: func(item *nav.TraverseItem) error {
actualNoChildren := len(item.Children)
Expand Down
2 changes: 1 addition & 1 deletion xfs/nav/filter-init.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func InitFiltersHookFn(o *TraverseOptions, frame *navigationFrame) {
return nil
},
}
frame.raw = *decorator
frame.raw = decorator
frame.decorate("init-current-filter 🎁", decorator)
}

Expand Down
8 changes: 4 additions & 4 deletions xfs/nav/filter-regex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var _ = Describe("FilterRegex", Ordered, func() {
o.Store.Subscription = entry.subscription
o.Store.FilterDefs = filterDefs
o.Store.DoExtend = true
o.Callback = nav.LabelledTraverseCallback{
o.Callback = &nav.LabelledTraverseCallback{
Label: "test regex filter callback",
Fn: func(item *nav.TraverseItem) error {
GinkgoWriter.Printf(
Expand Down Expand Up @@ -259,7 +259,7 @@ var _ = Describe("FilterRegex", Ordered, func() {
o.Store.Subscription = entry.subscription
o.Store.FilterDefs = filterDefs
o.Store.DoExtend = true
o.Callback = nav.LabelledTraverseCallback{
o.Callback = &nav.LabelledTraverseCallback{
Label: "test regex filter callback",
Fn: func(item *nav.TraverseItem) error {
actualNoChildren := len(item.Children)
Expand Down Expand Up @@ -386,7 +386,7 @@ var _ = Describe("FilterRegex", Ordered, func() {
o.Notify.OnBegin = begin("🧲")
o.Store.Subscription = nav.SubscribeFolders
o.Store.FilterDefs = filterDefs
o.Callback = nav.LabelledTraverseCallback{
o.Callback = &nav.LabelledTraverseCallback{
Label: "test regex filter callback",
Fn: func(_ *nav.TraverseItem) error {
return nil
Expand Down Expand Up @@ -442,7 +442,7 @@ var _ = Describe("FilterRegex", Ordered, func() {
o.Store.Subscription = nav.SubscribeFoldersWithFiles
o.Store.FilterDefs = filterDefs
o.Store.DoExtend = true
o.Callback = nav.LabelledTraverseCallback{
o.Callback = &nav.LabelledTraverseCallback{
Label: "test regex filter callback",
Fn: func(_ *nav.TraverseItem) error {
return nil
Expand Down
62 changes: 31 additions & 31 deletions xfs/nav/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type naviTE struct {
visit bool
caseSensitive bool
subscription nav.TraverseSubscription
callback nav.LabelledTraverseCallback
callback *nav.LabelledTraverseCallback
mandatory []string
prohibited []string
expectedNoOf expectedNo
Expand Down Expand Up @@ -150,10 +150,10 @@ func begin(em string) nav.BeginHandler {
}
}

func universalCallback(name string, extended bool) nav.LabelledTraverseCallback {
func universalCallback(name string, extended bool) *nav.LabelledTraverseCallback {
ex := lo.Ternary(extended, "-EX", "")

return nav.LabelledTraverseCallback{
return &nav.LabelledTraverseCallback{
Label: "test universal callback",
Fn: func(item *nav.TraverseItem) error {
depth := lo.TernaryF(extended,
Expand All @@ -174,10 +174,10 @@ func universalCallback(name string, extended bool) nav.LabelledTraverseCallback
}
}

func universalCallbackNoAssert(name string, extended bool) nav.LabelledTraverseCallback {
func universalCallbackNoAssert(name string, extended bool) *nav.LabelledTraverseCallback {
ex := lo.Ternary(extended, "-EX", "")

return nav.LabelledTraverseCallback{
return &nav.LabelledTraverseCallback{
Label: "test universal callback",
Fn: func(item *nav.TraverseItem) error {
depth := lo.TernaryF(extended,
Expand All @@ -193,10 +193,10 @@ func universalCallbackNoAssert(name string, extended bool) nav.LabelledTraverseC
}
}

func foldersCallback(name string, extended bool) nav.LabelledTraverseCallback {
func foldersCallback(name string, extended bool) *nav.LabelledTraverseCallback {
ex := lo.Ternary(extended, "-EX", "")

return nav.LabelledTraverseCallback{
return &nav.LabelledTraverseCallback{
Label: "folders callback",
Fn: func(item *nav.TraverseItem) error {
depth := lo.TernaryF(extended,
Expand All @@ -221,10 +221,10 @@ func foldersCallback(name string, extended bool) nav.LabelledTraverseCallback {
}
}

func filesCallback(name string, extended bool) nav.LabelledTraverseCallback {
func filesCallback(name string, extended bool) *nav.LabelledTraverseCallback {
ex := lo.Ternary(extended, "-EX", "")

return nav.LabelledTraverseCallback{
return &nav.LabelledTraverseCallback{
Label: "files callback",
Fn: func(item *nav.TraverseItem) error {
GinkgoWriter.Printf("---> 🌙 FILES//%v-CALLBACK%v: '%v'\n", name, ex, item.Path)
Expand All @@ -240,8 +240,8 @@ func filesCallback(name string, extended bool) nav.LabelledTraverseCallback {

// === scope

func universalScopeCallback(name string) nav.LabelledTraverseCallback {
return nav.LabelledTraverseCallback{
func universalScopeCallback(name string) *nav.LabelledTraverseCallback {
return &nav.LabelledTraverseCallback{
Label: "test universal callback",
Fn: func(item *nav.TraverseItem) error {
GinkgoWriter.Printf("---> 🌠 UNIVERSAL//%v-CALLBACK-EX item-scope: (%v) '%v'\n",
Expand All @@ -253,8 +253,8 @@ func universalScopeCallback(name string) nav.LabelledTraverseCallback {
}
}

func foldersScopeCallback(name string) nav.LabelledTraverseCallback {
return nav.LabelledTraverseCallback{
func foldersScopeCallback(name string) *nav.LabelledTraverseCallback {
return &nav.LabelledTraverseCallback{
Label: "test folders callback",
Fn: func(item *nav.TraverseItem) error {
GinkgoWriter.Printf("---> 🌟 FOLDERS//%v-CALLBACK-EX item-scope: (%v) '%v'\n",
Expand All @@ -267,8 +267,8 @@ func foldersScopeCallback(name string) nav.LabelledTraverseCallback {
}
}

func filesScopeCallback(name string) nav.LabelledTraverseCallback {
return nav.LabelledTraverseCallback{
func filesScopeCallback(name string) *nav.LabelledTraverseCallback {
return &nav.LabelledTraverseCallback{
Label: "test files callback",
Fn: func(item *nav.TraverseItem) error {
GinkgoWriter.Printf("---> 🌬️ FILES//%v-CALLBACK-EX item-scope: (%v) '%v'\n",
Expand All @@ -283,8 +283,8 @@ func filesScopeCallback(name string) nav.LabelledTraverseCallback {

// === sort

func universalSortCallback(name string) nav.LabelledTraverseCallback {
return nav.LabelledTraverseCallback{
func universalSortCallback(name string) *nav.LabelledTraverseCallback {
return &nav.LabelledTraverseCallback{
Label: "test universal callback",
Fn: func(item *nav.TraverseItem) error {
GinkgoWriter.Printf("---> 💚 UNIVERSAL//%v-SORT-CALLBACK-EX(scope:%v, depth:%v) '%v'\n",
Expand All @@ -296,8 +296,8 @@ func universalSortCallback(name string) nav.LabelledTraverseCallback {
}
}

func foldersSortCallback(name string) nav.LabelledTraverseCallback {
return nav.LabelledTraverseCallback{
func foldersSortCallback(name string) *nav.LabelledTraverseCallback {
return &nav.LabelledTraverseCallback{
Label: "test folders sort callback",
Fn: func(item *nav.TraverseItem) error {
GinkgoWriter.Printf("---> 💜 FOLDERS//%v-SORT-CALLBACK-EX '%v'\n",
Expand All @@ -310,8 +310,8 @@ func foldersSortCallback(name string) nav.LabelledTraverseCallback {
}
}

func filesSortCallback(name string) nav.LabelledTraverseCallback {
return nav.LabelledTraverseCallback{
func filesSortCallback(name string) *nav.LabelledTraverseCallback {
return &nav.LabelledTraverseCallback{
Label: "test files sort callback",
Fn: func(item *nav.TraverseItem) error {
GinkgoWriter.Printf("---> 💙 FILES//%v-SORT-CALLBACK-EX '%v'\n",
Expand All @@ -324,8 +324,8 @@ func filesSortCallback(name string) nav.LabelledTraverseCallback {
}
}

func universalDepthCallback(name string, maxDepth int) nav.LabelledTraverseCallback {
return nav.LabelledTraverseCallback{
func universalDepthCallback(name string, maxDepth int) *nav.LabelledTraverseCallback {
return &nav.LabelledTraverseCallback{
Label: "test universal depth callback",
Fn: func(item *nav.TraverseItem) error {
if item.Extension.Depth <= maxDepth {
Expand All @@ -339,10 +339,10 @@ func universalDepthCallback(name string, maxDepth int) nav.LabelledTraverseCallb
}
}

func foldersCaseSensitiveCallback(first, second string) nav.LabelledTraverseCallback {
func foldersCaseSensitiveCallback(first, second string) *nav.LabelledTraverseCallback {
recording := make(recordingMap)

return nav.LabelledTraverseCallback{
return &nav.LabelledTraverseCallback{
Label: "test folders case sensitive callback",
Fn: func(item *nav.TraverseItem) error {
recording[item.Path] = len(item.Children)
Expand All @@ -368,8 +368,8 @@ func foldersCaseSensitiveCallback(first, second string) nav.LabelledTraverseCall

// === skip

func skipFolderCallback(skip, exclude string) nav.LabelledTraverseCallback {
return nav.LabelledTraverseCallback{
func skipFolderCallback(skip, exclude string) *nav.LabelledTraverseCallback {
return &nav.LabelledTraverseCallback{
Label: "test skip folder callback",
Fn: func(item *nav.TraverseItem) error {
GinkgoWriter.Printf(
Expand All @@ -385,8 +385,8 @@ func skipFolderCallback(skip, exclude string) nav.LabelledTraverseCallback {
}
}

func boostCallback(name string) nav.LabelledTraverseCallback {
return nav.LabelledTraverseCallback{
func boostCallback(name string) *nav.LabelledTraverseCallback {
return &nav.LabelledTraverseCallback{
Label: "test boost callback",
Fn: func(item *nav.TraverseItem) error {
fmt.Printf("---> ⏩ ON-boost-CALLBACK(%v) '%v'\n", name, item.Path)
Expand Down Expand Up @@ -429,10 +429,10 @@ func readDirFakeErrorAt(name string) func(dirname string) ([]fs.DirEntry, error)
}
}

func errorCallback(name string, extended, hasError bool) nav.LabelledTraverseCallback {
func errorCallback(name string, extended, hasError bool) *nav.LabelledTraverseCallback {
ex := lo.Ternary(extended, "-EX", "")

return nav.LabelledTraverseCallback{
return &nav.LabelledTraverseCallback{
Label: "test error callback",
Fn: func(item *nav.TraverseItem) error {
GinkgoWriter.Printf("---> 🔥 %v-CALLBACK%v: '%v'\n", name, ex, item.Path)
Expand Down
4 changes: 2 additions & 2 deletions xfs/nav/marshal-state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var _ = Describe("MarshalOptions", Ordered, func() {
o.Store.Subscription = nav.SubscribeAny
o.Store.DoExtend = true
o.Store.FilterDefs = &filterDefs
o.Callback = nav.LabelledTraverseCallback{
o.Callback = &nav.LabelledTraverseCallback{
Label: "test marshal state callback",
Fn: func(_ *nav.TraverseItem) error {
return nil
Expand Down Expand Up @@ -98,7 +98,7 @@ var _ = Describe("MarshalOptions", Ordered, func() {
o.Persist.Format = entry.format
o.Store.DoExtend = true
o.Store.FilterDefs = &filterDefs
o.Callback = nav.LabelledTraverseCallback{
o.Callback = &nav.LabelledTraverseCallback{
Label: "test marshal state callback",
Fn: func(item *nav.TraverseItem) error {
return nil
Expand Down
5 changes: 3 additions & 2 deletions xfs/nav/navigation-async-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
)

type TraverseItemInput struct {
Item *TraverseItem
Fn TraverseCallback
Item *TraverseItem
Label string
Fn TraverseCallback
}
type TraverseItemJob = boost.Job[TraverseItemInput]
type TraverseItemJobStream = boost.JobStream[TraverseItemInput]
Expand Down
6 changes: 3 additions & 3 deletions xfs/nav/navigation-frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ type navigationFrame struct {
root utils.VarProp[string]
currentPath utils.VarProp[string]
listener *navigationListener
raw LabelledTraverseCallback // un-decorated (except for filter) client callback
client LabelledTraverseCallback // decorate-able client callback
raw *LabelledTraverseCallback // un-decorated (except for filter) client callback
client *LabelledTraverseCallback // decorate-able client callback
filters *NavigationFilters
notifiers notificationsSink
periscope *navigationPeriscope
Expand Down Expand Up @@ -43,7 +43,7 @@ func (f *navigationFrame) decorate(_ string, decorator *LabelledTraverseCallback
// stack overflow due to infinite recursion. Its easy to search when decoration is
// occurring in the code base, just search for decorate or go to references.
//
f.client = *decorator
f.client = decorator
}

func (f *navigationFrame) save(active *ActiveState) {
Expand Down
12 changes: 6 additions & 6 deletions xfs/nav/navigation-listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
ListenRetired // conditional listening is now deactivated
)

type navigationListeningStates map[ListeningState]LabelledTraverseCallback
type navigationListeningStates map[ListeningState]*LabelledTraverseCallback

type listenStatesParams struct {
// currently used for makeStates and listener.decorate
Expand All @@ -45,7 +45,7 @@ type listenStatesParams struct {
type navigationListener struct {
state ListeningState
states navigationListeningStates
current LabelledTraverseCallback
current *LabelledTraverseCallback
resumeStack *collections.Stack[*ListenTriggers]
triggers *ListenTriggers
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func (l *navigationListener) makeStates(params *listenStatesParams) {
//
ListenDeaf: params.frame.raw,

ListenFastward: LabelledTraverseCallback{
ListenFastward: &LabelledTraverseCallback{
Label: "ListenFastward decorator",
Fn: func(item *TraverseItem) error {
// fast forwarding to resume point
Expand All @@ -100,7 +100,7 @@ func (l *navigationListener) makeStates(params *listenStatesParams) {
},
},

ListenPending: LabelledTraverseCallback{
ListenPending: &LabelledTraverseCallback{
Label: "ListenPending decorator",
Fn: func(item *TraverseItem) error {
// listening not yet started
Expand All @@ -120,7 +120,7 @@ func (l *navigationListener) makeStates(params *listenStatesParams) {
},
},

ListenActive: LabelledTraverseCallback{
ListenActive: &LabelledTraverseCallback{
Label: "ListenActive decorator",
Fn: func(item *TraverseItem) error {
// listening
Expand All @@ -138,7 +138,7 @@ func (l *navigationListener) makeStates(params *listenStatesParams) {
},
},

ListenRetired: LabelledTraverseCallback{
ListenRetired: &LabelledTraverseCallback{
Label: "ListenRetired decorator",
Fn: func(_ *TraverseItem) error {
return xi18n.NewTerminateTraverseError()
Expand Down
4 changes: 2 additions & 2 deletions xfs/nav/navigation-listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = Describe("Listener", Ordered, func() {
}
}
o.Store.DoExtend = entry.extended
o.Callback = nav.LabelledTraverseCallback{
o.Callback = &nav.LabelledTraverseCallback{
Label: "test listener callback",
Fn: func(item *nav.TraverseItem) error {
GinkgoWriter.Printf("---> 🔊 LISTENING-CALLBACK: name: '%v'\n",
Expand Down Expand Up @@ -311,7 +311,7 @@ var _ = Describe("Listener", Ordered, func() {
GinkgoWriter.Printf("===> ⛔ Stop Listening: '%v'\n", description)
}
o.Store.DoExtend = true
o.Callback = nav.LabelledTraverseCallback{
o.Callback = &nav.LabelledTraverseCallback{
Label: "Listener Test Callback",
Fn: func(item *nav.TraverseItem) error {
GinkgoWriter.Printf("---> 🔊 LISTENING-CALLBACK: name: '%v'\n",
Expand Down
Loading