Example #1
0
File: app.go Project: kego/ke
func (app *App) Init(ctx context.Context) {

	n := flux.NewNotifier()
	app.Notifier = n
	app.Watcher = n

	app.Package = NewPackageStore(ctx)
	app.Editors = NewEditorStore(ctx)
	app.Branches = NewBranchStore(ctx)
	app.Nodes = NewNodeStore(ctx)
	app.Panels = NewPanelStore(ctx)
	app.Types = NewTypeStore(ctx)
	app.Data = NewDataStore(ctx)
	app.Misc = NewMiscStore(ctx)
	app.Rule = NewRuleStore(ctx)
	app.Actions = NewActionStore(ctx)
	app.Files = NewFileStore(ctx)
	app.Env = NewEnvStore(ctx)
	app.Dispatcher = flux.NewDispatcher(
		app.Notifier, // NotifierInterface
		app.Package,  // StoreInterface...
		app.Editors,
		app.Branches,
		app.Nodes,
		app.Panels,
		app.Types,
		app.Data,
		app.Misc,
		app.Rule,
		app.Actions,
		app.Files,
		app.Env,
	)
}
Example #2
0
func TestDispatcher_Notify(t *testing.T) {
	m := gomock.NewController(t)
	defer m.Finish()
	not := mock_flux.NewMockNotifierInterface(m)
	a := &st1{}
	gomock.InOrder(not.EXPECT().NotifyWithData("a", notif1{}, nil).Return(closedChannel()))
	d := flux.NewDispatcher(not, a)
	done := d.Dispatch(false)
	<-done
}
Example #3
0
func TestDispatcher(t *testing.T) {

	a := &App{}
	a.Messages = &MessageStore{Store: &flux.Store{}, app: a}
	a.Topics = &TopicStore{Store: &flux.Store{}, app: a}
	a.Dispatcher = flux.NewDispatcher(nil, a.Messages, a.Topics)

	done := a.Dispatcher.Dispatch(&AddMessage{Message: "a"})
	<-done
	done = a.Dispatcher.Dispatch(&AddTopic{Topic: "b", Message: "c"})
	<-done
	msg := a.Messages.GetMessages()
	assert.Equal(t, []string{"a", "c"}, msg)
}
Example #4
0
func TestFlights(t *testing.T) {

	a := &Flights{}
	a.Country = &CountryStore{app: a, Store: &flux.Store{}}
	a.City = &CityStore{app: a, Store: &flux.Store{}}
	a.Price = &PriceStore{app: a, Store: &flux.Store{}}
	a.Dispatcher = flux.NewDispatcher(nil, a.Country, a.City, a.Price)

	done := a.Dispatcher.Dispatch(&UpdateCountryAction{Country: "France"})
	<-done

	assert.Equal(t, "France", a.Country.GetCountry())
	assert.Equal(t, "Paris", a.City.GetCity())
	assert.Equal(t, "€100", a.Price.GetPrice())
}