-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
54 lines (42 loc) · 1.54 KB
/
app.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
package immersim
import (
"github.com/studiolambda/immersim/event"
"github.com/studiolambda/immersim/storage"
)
type Application struct {
storage *storage.Storage
events *event.Events
}
func NewApplication(storage *storage.Storage, events *event.Events) *Application {
return &Application{
storage: storage,
events: events,
}
}
func (application *Application) Read(resource string) (any, error) {
return application.storage.Read(resource)
}
func (application *Application) Write(resource string, value any) error {
return application.storage.Write(resource, value)
}
func (application *Application) Action(resource string, action string, payload any) {
application.events.Emit(event.Action(resource, action), payload)
}
func (application *Application) SubscribeChanges(resource string, listener chan any) {
application.events.Subscribe(event.Changed(resource), listener)
}
func (application *Application) UnsubscribeChanges(resource string, listener chan<- any) {
application.events.Unsubscribe(event.Changed(resource), listener)
}
func (application *Application) SubscribeAction(resource string, action string, listener chan any) {
application.events.Subscribe(event.Action(resource, action), listener)
}
func (application *Application) UnsubscribeAction(resource string, action string, listener chan<- any) {
application.events.Unsubscribe(event.Action(resource, action), listener)
}
func (application *Application) Start() {
application.storage.Start(application.events)
}
func (application *Application) Stop() {
application.storage.Stop()
}