Open albrow opened 9 years ago
Thanks for submitting this for feedback. The structure of the events struct looks good, as well as the interface setup.
Clarification: Would the Events() method be used to declare the events a view should have onload? What if we want to add or remove events based on user interactions with the view?
@fabioberger thanks for your comments. Yeah the Events
method is for declaring events the view should have on load. If you want to add or remove events manually, it's not hard to do it with the dom package. It would look something like
view.Element().AddEventListener("click", true, func(event dom.Event){
// Do something with event
})
I might add some utilities for adding and removing events since currently the RemoveEventListener
function requires a js.Object
as an argument. It's a little weird and not go-like. If I add this it's just going to be a really lightweight wrapper.
Thinking I'm most definitely going to create a separate event package, so keep an eye out for that!
Awesome, then this proposal looks great, I'll be excited to use it in production. Its a much cleaner, pragmatic approach then my current solution. Great work!
I think we'll take inspiration from backbone here, since they also have template language agnostic views. What I'm thinking right now is that there will be a way to specify events for each view. Possibly via an
Events
method andEvent
type.The view package can then check if you have implemented the
Events
method with an type assertion.Finally there could be a
DelegateEvents
helper function which takes anEventer
as an argument.Here's an example of how you might add events to a TodoView:
The advantage to this approach is that the
Events
method is tied to aView
type declaration, and not to a specificView
instance. This is the behavior that is more commonly wanted.Depending on how this all feels, I may split events into their own package and import the event package into the view package for delegating events to views.