-
Notifications
You must be signed in to change notification settings - Fork 0
/
featuresManager.go
33 lines (27 loc) · 1.22 KB
/
featuresManager.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
package engine
import "github.com/cadmean-ru/amphion/frontend"
//FeaturesManager is responsible for keeping track of what frontend features are available and invoking them.
//Frontend should register all features that it provides. Then those features become available and can be invoked.
type FeaturesManager struct {
features map[FeatureCode]frontend.FeatureDelegate
}
//InvokeFeature invokes the feature with the specified FeatureCode if is available.
//Passes the specified data to the feature delegate and returns the result.
func (f *FeaturesManager) InvokeFeature(code FeatureCode, data interface{}) interface{} {
if feat, ok := f.features[code]; ok {
return feat.OnInvoke(data)
}
return nil
}
//IsFeatureAvailable checks if feature with the specified FeatureCode is available (provided by the frontend).
func (f *FeaturesManager) IsFeatureAvailable(code FeatureCode) bool {
_, ok := f.features[code]
return ok
}
//RegisterFeatureDelegate should be called by the frontend.
func (f *FeaturesManager) RegisterFeatureDelegate(code FeatureCode, delegate frontend.FeatureDelegate) {
f.features[code] = delegate
}
func newFeaturesManager() *FeaturesManager {
return &FeaturesManager{features: map[FeatureCode]frontend.FeatureDelegate{}}
}