-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-navigator.go
86 lines (69 loc) 路 1.81 KB
/
new-navigator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package nav
import (
"github.com/snivilised/extendio/i18n"
)
type navigatorFactory struct{}
func (f navigatorFactory) new(o *TraverseOptions) TraverseNavigator {
impl := navigatorImplFactory{}.new(o)
nc := &navigationController{
impl: impl,
}
booter := bootstrapper{
o: o,
nc: nc,
}
booter.init()
return nc
}
func (f navigatorFactory) fromOptionsFn(fn ...TraverseOptionFn) TraverseNavigator {
o := composeTraverseOptions(fn...)
if o.Callback.Fn == nil {
panic(i18n.NewMissingCallbackError())
}
return f.new(o)
}
func (f navigatorFactory) fromProvidedOptions(o *TraverseOptions) TraverseNavigator {
nav := f.new(o)
o.afterUserOptions()
return nav
}
type navigatorImplFactory struct{}
func (f navigatorImplFactory) new(o *TraverseOptions) navigatorImpl {
var (
impl navigatorImpl
samplingActive = o.Store.Sampling.SampleType != SampleTypeUnsetEn
filteringActive = o.isFilteringActive()
samplingFilterActive = samplingActive && filteringActive
doInvoke = o.Store.Subscription != SubscribeFiles
agent = newAgent(&newAgentParams{
o: o,
doInvoke: doInvoke,
handler: ¬ifyCallbackErrorHandler{},
samplingFilterActive: samplingFilterActive,
})
n = navigator{
o: o,
agent: agent,
samplingActive: samplingActive,
filteringActive: filteringActive,
samplingFilterActive: samplingFilterActive,
}
)
switch o.Store.Subscription {
case SubscribeAny:
impl = &universalNavigator{
navigator: n,
}
case SubscribeFolders, SubscribeFoldersWithFiles:
impl = &foldersNavigator{
navigator: n,
}
case SubscribeFiles:
impl = &filesNavigator{
navigator: n,
}
default:
panic(ErrUndefinedSubscriptionType)
}
return impl
}