Multiple framework events triggering one command
I have a situation where, in the app startup sequence, an event
triggers a command (that loads a set of data):
// in context commandMap.mapEvent(DatabaseEvent.READY,
LoadContactListCommand, DatabaseEvent, true);
Later when the data set changes (an item is deleted), an event
comes back that the delete succeeded, and I'm thinking of using
that to trigger the re-loading of the data set:
// in context commandMap.mapEvent(CompleteEvent.DELETE_COMPLETE,
LoadContactListCommand, CompleteEvent);
Also (in code I haven't added yet) when an item is edited, I'd
also like to re-load the data set, so presumably I'd need another
mapping:
// in context commandMap.mapEvent(CompleteEvent.EDIT_COMPLETE,
LoadContactListCommand, CompleteEvent);
My question is, is it weird that I have multiple events that trigger the same command? Or does that seem like the right way to do it? Also, does it make sense to have all those mappings in the context?
What alternative approaches should I consider (i.e. how do you
do this)?
For example, one alternative I've thought of is to create a "load
data" event specifically for triggering the command, and just
dispatch that event at times when it's needed. But then I'd need to
write a set of listeners that just get the "complete" events from
the services, and dispatch the "load data" event to trigger the
command. Or else I could just make the various services dispatch
the "load data" event instead of their separate "complete" events
-- but that seems a little weird to me, like putting controller
logic into the services.
Thoughts?
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Till Schneidere... on Feb 26, 2010 @ 12:46 PM
As I see it, there's nothing weird with your approach.
Events are gestures to which commands react. It seems natural to me
that multiple gestures might cause the same reaction, so I map the
same command to multiple events quite often.
hope that helps,
till
Support Staff 2 Posted by Joel Hooks on Feb 26, 2010 @ 04:27 PM
I totally agree Till. Commands encapsulate an action that should be able to be triggered from anywhere by anything as appropriate.
3 Posted by Paul Robertson on Feb 26, 2010 @ 09:27 PM
Thanks for the advice!