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
Better message handling #145
Comments
Agree. |
This is pretty nice idea. It would make the I'll revisit this proposal when we're thinking of doing another major release. Thanks! |
I'd encourage you to think about it in as a minor enhancement in the interm. You could support both objects and functions going forward and deprecate the use of direct functions at a later date. It would help with the upgrade path too, especially for those who have large systems. |
@zephraph Would you be willing to put together a pull request for this enhancement? We'd like to make sure its compatible with IE8 (no ES5) and we can forgo removing the messages array for now. |
Sure thing. |
I was going back through this in prep for the PR and noticed I left off an example of event handling. Delegation of events is a bit trickier because there's not some set string to key off of. You could key off of One way to achieve this would be to have a special method on the object that would determine which event handler should be called. return {
onclick: {
delegate: function(event, element, dataType) {
return dataType || event.target;
},
btn: function(event, element, dataType) {} // Where btn is a dataType
}
} I'm not sure if I like this. Ultimately though, I feel like there should between some semblance of consistent behavior between modules and event handlers. Is there a better way to handle this? |
|
There might also be a need to add multiple message handlers. Using the An alternative might be to allow object literals in the For example: messages = [
'normalmessage', // Invoke 'onmessage'
{ 'anothermessage': [ 'callbackone', 'callbacktwo' ] } // Invoke all callbacks for message 'anothermessage'.
] Currently I've written a service with a |
Currently when one wants to handle messages or events they add something like the following
Something like that, right? Well, maybe instead of a
switch
anif else
statements is used. Regardless, that breakdown is up to the individual who implements the module/behavior/service in question.I pulled this straight from the docs:
This interface doesn't naturally support that. On the contrary, I feel like it encourages the bad practice of handling all cases directly inside that method.
I'm proposing an improvement to message/event handling where an object can be passed to
on*
as an alternative to passing a function.Example
This interface ensures that there's a function that handles every message instead of a single function that handles all messages. There's no noisy
if
orswitch
statements to deal with. The other thing this setup makes me think is, now that it's known what messages are being handled by the T3 construct, it's not necessary to specifymessages
at all because that'd just be redundant. T3 can just scrape the messages off the onmessage object.My current proposal isn't to get rid of
messages
or the fact thatonmessage
oronclick
can be a function. It's really just the addition for something likeonmessage
to be an object. Though, I will say that given the next "major" release, which might be a while from now, it would be good to consider the former points.Thoughts?
The text was updated successfully, but these errors were encountered: