github.com/soypat/vectytemplater@v0.0.0-20220501050640-d40b24e35168/_templates/default/store/store.go (about) 1 package store 2 3 import ( 4 "vecty-templater-project/store/actions" 5 "vecty-templater-project/store/storeutil" 6 ) 7 8 var ( 9 Ctx actions.Context 10 Items []string 11 12 Listeners = storeutil.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 30 default: 31 panic("unknown action selected!") 32 } 33 34 Listeners.Fire(action) 35 }