This post is great! If your event cases grow even farther than click and input, you can also implement dynamic dispatch to keep the complexity of handleEvent down:
consthandler={handleEvent(event){returnthis[`${event.type}Event`]&&// ensure that you don't throw if the function doesn't exist. // Unless you prefer to surface those events, but you could also convert this to a ternary or `if-else` to log when a type you weren't expecting is sent through.this[`${event.type}Event`](event);}clickEvent(event){/* ... */}inputEvent(event){/* ... */}submitEvent(event){/* ... */}dragEvent(event){/* yaaas! */}techTalkEvent(event){/* oooh, **takes notes**... */}}
Oh yeah, and you can even assign different responsibilities to multiple handlers, then programmatically split up the behaviors of your UI, without ever having to worry about the memory or performance impacts of this.bind. AND!! The VM is smart enough not to assign the same handler to the same event more than once! handleEvent is LITERALLY the best.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This post is great! If your event cases grow even farther than
click
andinput
, you can also implement dynamic dispatch to keep the complexity ofhandleEvent
down:Oh yeah, and you can even assign different responsibilities to multiple handlers, then programmatically split up the behaviors of your UI, without ever having to worry about the memory or performance impacts of
this.bind
. AND!! The VM is smart enough not to assign the same handler to the same event more than once!handleEvent
is LITERALLY the best.