github.com/soypat/vectytemplater@v0.0.0-20220501050640-d40b24e35168/_templates/websocket-cli/app/store/store.go (about) 1 package store 2 3 import ( 4 "vecty-templater-project/app/store/actions" 5 "vecty-templater-project/model" 6 ) 7 8 var ( 9 Ctx actions.Context 10 Items []model.Item 11 ServerReply string 12 Listeners = newListenerRegistry() 13 ) 14 15 func OnAction(action interface{}) { 16 switch a := action.(type) { 17 case *actions.NewItem: 18 Items = append(Items, a.Item) 19 20 case *actions.PageSelect: 21 oldCtx := Ctx 22 Ctx = actions.Context{ 23 Page: a.Page, 24 Referrer: &oldCtx, 25 } 26 27 case *actions.Back: 28 Ctx = *Ctx.Referrer 29 case *actions.Refresh: 30 // do nothing, just fire listeners to refresh page. 31 default: 32 panic("unknown action selected!") 33 } 34 35 Listeners.Fire(action) 36 }