adds Context#execute and passes payloads as parameters instead of single...#22
adds Context#execute and passes payloads as parameters instead of single...#22creynders wants to merge 1 commit intoGeppettoJS:masterfrom
Conversation
|
Forgot to add that obviously I still need to update the readme. I haven't already, since I wanted to see how this plays out. |
|
Awesome... I think this is the beginning of the first big discussion about what Geppetto's philosophy really should be. I had my own ideas, based on my "translation" of Robotlegs into JavaScript. But with some of the changes that you mentioned made it into RL 2.0 (after some debate) I'd like to open up my mind to these new possibilities. We've been using Geppetto as-is with no problems within my company, but as some smart folks have stated, To build something truly reusable, you must convince three different audiences to use it thoroughly first. So... on to the debate! 1. Adding an
|
|
Heheh, I love this kind of debates. Context#Execute
Yes, when called from commands. Context.extend({
commands:{
'qux': [
FooCommand,
BarCommand,
BazCommand
]
}
})You can do: //wiring
Context.extend({
comands:{
'qux' : QuxCommand
}
});
//QuxCommand
function execute(){
this.context.execute([
FooCommand,
BarCommand,
BazCommand
]);
}This is useful in cases where However
Quite right. Hadn't thought of that. That is definitely a serious concern. To me it's so evident not to use it in views, that I hadn't realized people will be abusing it. Maps to arrays
Nothing prohibits you from using a map, just as you did before. I too tend to use VO's, but there are times when it is easier and more flexible to simply pipe all arguments through. Event names no longer passed to callbacks
Ah yes, of course. Hmmm... need to think on that. Obviously it's possible to pass the event name as a parameter, but I'm not really fond of that. |
Aha! I definitely see the value there.
It's been my experience that developers will often find the path of least resistance, even if it means ignoring best practices. So better not to give them the gun, instead of advising them not to shoot themselves in the foot. Here's a crazy idea. What if Geppetto injected the command with its own function execute() {
this.executeOther([
FooCommand,
BarCommand,
BazCommand
]);
}This special |
|
Regarding the chaining of commands, and executing one command from another, my team had some concerns:
...and...
So now I'm leaning more towards not including this feature. @creynders do you have any real-world scenarios where this would be useful? I understand the hypothetical advantage, but just wondering how this would manifest itself in the real world. |
Agreed. It's why we don't advertise some of the possibilities in RL, but merely mention them, figuring that only people who know the framework and its paradigm well enough will understand and realize the potential use cases.
That's definitely an option. Maybe
I think we use commands differently. To me commands perform no real work, they assemble, construct and relay.
Synchronously, i.e. immediately. When I want to chain asynchronous operations I use a finite state machine or promises.
I don't see how this would sacrifice flexibility? On the contrary. |
|
So, I've been thinking this through in the past weeks. The more I think about it, the more convinced I get that my initial gut feeling revolves around symmetry and paradigm concordance, more than the above mentioned benefits. I think the whole events thing should be brought back to basics and the abstraction layer on top of context.trigger('foo', 'bar', 'baz', 'qux');Commands' {
name: 'foo',
data: [ 'bar', 'baz', 'qux' ]
}Then regarding the redispatching/relaying of events, IMO there's always a better, more elegant solution. But if really necessary we could provide an extra method: var handler = function(eventName, bar, baz, qux){
}
context.relay('foo', handler);And I'm convinced now, we don't need Now there's several reasons why I think we should remove the abstraction layer on top of
|
|
@creynders Is this PR obsolete now? |
|
@geekdave The PR definitely is. But I would like to continue the discussion on the benefits/disadvantages of removing the abstraction layer on top of Backbone.Events. Maybe a separate issue? |
|
@creynders Sorry for the delay in responding. We are just now getting around to refactoring our code to use the new DI API.
Will close this one for now...
Agreed. Please log a separate issue with your proposal and we can discuss it there. |
... object
Proposed changes:
Adds an
executemethod to the context, to allow direct sequential synchronous execution of commands:Modifies how payloads are passed to commands and callbacks:
in case of
commands are injected with an
eventobject with following structure:commands also receive the payload as arguments to the
executefunction:callbacks receive the payload as arguments, just as a command's
executefunctionThrows concrete error when a command has no
executemethodThen, a bit of the reasoning:
I opted for
eventwithnameanddatato keep the modification as small as possible. I.e. if you'd like to update your <=0.6.2 commands to this version, "all" you'll need to do is swapthis.eventNamewiththis.event.nameandthis.eventDatawiththis.event.dataA major breaking change is the fact that event names are no longer passed to callbacks. Do you think this is a problem? Commands still have access to the event name through the
eventobject, but views won't. Would this be something you can live with? Personally I never, ever need event names in my handlers, but YMMV.BTW I had to drop the blanket coverage treshold to 97, otherwise it failed. Do you think this is due to the introduction of the pseudo-private
_executemethod?see #18
see #20