-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
event: overhaul api #196
event: overhaul api #196
Conversation
- adds type safe bindings / triggers - decreases api surface considerably - loops replaced with concurrent executions
1. unsafeBind(id,handler,interface{}), 2. globalBind(typedPayload) 3. bind(typedCaller,typedPayload) This migrates all packages but examples, entities, and joystickviz
- adjusts the loading scene to not use a loop. - keyboard-viz example working
event/bind.go
Outdated
eb.Bind(name, 0, fn) | ||
// A Bindable is a strongly typed callback function to be executed on Trigger. It must be paired | ||
// with an event registered via RegisterEvent. | ||
type Bindable[Payload any, C any] func(C, Payload) Response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate to say it but I think we should change this to not flip args.
When newer implementers are using this the error messages are a bit confusing due to the flip.
Take for example this error message I got while going through the click propagation example:
.\main.go:56:48: type func(me *"github.com/oakmound/oak/v3/mouse".Event, box *hoverButton) event.Response of func(me *mouse.Event, box hoverButton) event.Response {…} does not match inferred type event.Bindable["github.com/oakmound/oak/v3/mouse".Event, *hoverButton] for event.Bindable[vent, *hoverButton] for event.Bindable[Payload, C]
After writing a few its a pretty well known paradigm but it feels like if we are to make this switch it would be now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, you're suggesting:
--- a/event/bind.go
+++ b/event/bind.go
@@ -81,9 +81,9 @@ func (bus *Bus) Unbind(loc Binding) {
// A Bindable is a strongly typed callback function to be executed on Trigger. It must be paired
// with an event registered via RegisterEvent.
-type Bindable[Payload any, C any] func(C, Payload) Response
+type Bindable[C any, Payload any] func(C, Payload) Response
-func Bind[Payload any, C Caller](b Handler, ev EventID[Payload], c C, fn Bindable[Payload, C]) Binding {
+func Bind[C Caller, Payload any](b Handler, ev EventID[Payload], c C, fn Bindable[C, Payload]) Binding {
return b.UnsafeBind(ev.UnsafeEventID, c.CID(), func(c CallerID, h Handler, payload interface{}) Response {
typedPayload := payload.(Payload)
ent := h.GetCallerMap().GetEntity(c)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly!
How do you feel about that rewrite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good improvement; it won't require any refactoring either, as the type arguments should be implied from the inputs.
scene: Embed Eventhandler to allow for some embedded calls
…oak into feature/v4-eventskeys+examples
…oak into feature/v4-eventskeys+examples
Feature/v4 eventskeys+examples
Codecov Report
@@ Coverage Diff @@
## release/v4.0.0 #196 +/- ##
==================================================
- Coverage 92.39% 91.54% -0.85%
==================================================
Files 141 138 -3
Lines 6456 6222 -234
==================================================
- Hits 5965 5696 -269
- Misses 430 459 +29
- Partials 61 67 +6
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
TODO before completion: