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
Add _triggerEventOnBehaviors
to behaviors
#2884
Comments
To second that, I'm not a big fan of accessing view from behavior. Maybe a little more abstraction on all the cases that today force us to do |
I don't think that #2 is correct. Perhaps a failing test could prove this, but just looking through the parse behavior, the view that gets attached to the view's behavior is the same view that gets passed down to the nested behaviors. That said, it seems reasonable that a behavior could trigger up to it's nested behaviors, just like a view can trigger up to it's behaviors. However, we should probably make this implementation off of the |
Sorry @paulfalgout, you're absolutely right, #2 is incorrect. |
So...should I push a PR in (This would be my first marionette PR, excuse my ignorance) |
Yeah branch off of next and PR into it :-) You'll be happy to know that You'll also notice the behavior code is slightly different now and utilizes a mixin on the view. You may also want to check out the triggerMethod implementation inside view, as I suspect it has changed slightly. |
@paulfalgout your memory is superb. And, yes, giddy. Thanks 😄 |
So, I find myself nesting behaviors (mostly to keep my code DRY). Sadly, while I can do
this.view.triggerMethod
on my parent behavior to reach a nested behavior method1 this method is brittle for two reasons:2. More importantlythis.view
inside a behavior is not necessarily a Marionette.View, but a parent behavior, leading to unexpected...err...behaviorI think a quick and dirty fix would be to:
a. Add a reference to nested behaviors in the parent behavior. It should be as "easy" as editing
Marionette.Behaviors.parseBehaviors
b. Adding a triggerMethod method in Marionette.Behavior. Like this:
Look familiar? It should since I lifted them from Marionette.View almost verbatim2.
/cc @jasonLaster @samccone
1
_triggerEventOnBehaviors
reaches all views, since it iterates over the container view'sthis._behaviors
which holds references to al behaviors.2 Removed
this._triggerEventOnParentLayout(arguments[0], _.rest(arguments));
fromMarionette.View.triggerMethod
since it's not relevant.The text was updated successfully, but these errors were encountered: