-
Notifications
You must be signed in to change notification settings - Fork 230
Advanced syntax for declarative listeners #800
Comments
See #333 and #334 for the initial discussion of I agree there’s room for improvement here. Actually I find the Backbone’s I hesitate to overload this with more logic by introducing commas as another separator. If we deviate from Backbone here, we should probably come up with a better syntax instead of adding more logic to the existing syntax, which is fine for simple cases, but not extensible. (Of course there is backwards-compatibility.) In |
Oh, I missed that selectors can contain commas. It was a bad idea, ok. Let's leave As for Custom events channels It was shown, that it is easy to pass them to view, and you do not seem to have any objections. Also, note, that now the shown way is the only possible, as in Backbone 1.1.0 And also I agree with @akre54's opinion - listening to such local "channels" is not so rare issue to redefine So I think that using only "reserved" channel names didn't prove to be practical. Multiple events
But what another solution could be here at all? Taking additional advantage on last word in the string is not an option - because, even with fixed channel names, it still looks confusing. So this question is about "whether to introduce additional separator". I don't see another solution for declarative syntax. Grouping targets In that thread you propose approach based on You say that
It's ok, but why do you think that nesting in listen:
mediator: # which target?
"event1": "handler1" # which event type? : which handler function?
"event2": "handler2"
model:
"event3": "handler3"
"event4": "handler4" We read this exactly in order you describe. What can be more readable? Also, to understand what view listens to it is easier to just look what happens in single The only confusing thing here is - again - listening to view's own events. Of course, then someone could write something like this: listen:
mediator:
"event1": "handler1"
"event2 mediator": "handler2" But would it be really problem of Chaplin? Well... it's a huge comment. I hope the sense is still clear. |
I do like the |
Ok, I thought about it some more, and there is another idea: multiple events can be allowed inside groups. As in this case target will be already separated, we can still split events only by spaces. But in this case will be no ability to listen multiple events from view itself. |
You're saying something like this, right? class Button extends View
listen:
model:
'change': 'render'
'update eventa eventb': 'update' I don't see a reason why triggering |
It is only if we will deny to specify targets "inline", that is, refuse old syntax |
Personally I don't care about backwards compatibility for this case (and the Chaplin devs have proven they're willing to break bc for any good reason). It just means that you won't be able to use |
Very well, if bc is not so big deal, then I like this approach too. And also idea about multiple targets for same events becomes impossible, as targets are strictly separated. Thinking about it - perhaps, it's even better, because in real world such need is very rare, and in such case, as usual, "you should probably rethink you architecture". So, is there some another objections? @molily ? |
we can't break backwards compat for 1.x |
Then what about mixed approach from source comment? |
Definitely not. I use space-separated events all the time (and Chaplin's On Tue, May 27, 2014 at 3:59 PM, Jeron Diovis [email protected]:
|
Backbone’s object approach makes sense for simple key-value combinations. There are (at least) two ways to deal with more complex combinations: 1 nest objects
2 use flat lists
Example for version 2: listen: [
['event1 event2 eventN', 'target1 target2 targetN', 'handler1 handler2 handlerN']
…
] (Alternative order: targets, events, handlers) |
I like the nested object syntax the best, because it implies a hierarchy of properties on the view. The array syntax is confusing IMO. |
For now, declarative listeners only allows to subscribe to single event of single target. So when logic becomes more complex, all it quickly becomes very verbose or requires to refuse using declarative approach.
It's for discussion. I propose to allow following:
events
. But as it differs from Backbone'sevents
, I'm not sure about this.I will implement any of these points - need to know with which ones you agree.
The text was updated successfully, but these errors were encountered: