-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Adds onAttach triggerMethod. #1957
Conversation
636459e
to
83c144a
Compare
83c144a
to
66c717a
Compare
|
||
if (attachedRegion && this.triggerBeforeAttach) { | ||
displayedViews = [view].concat(_.result(view, '_getNestedViews')); | ||
this._triggerAttach(displayedViews, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a boolean flag in _triggerAttach
, we could pass the prefix string directly:
this._triggerAttach(displayedViews, 'before:');
this._triggerAttach(displayedViews, '');
This would make the _triggerAttach
role more clear, even without looking at it.
A couple notes:
The use case is when the user wants myRegion.show(myViewWithSomePlugin, { triggerAttach: true}) Should we add "before:detach" / "detach" events as well? These might be necessary to shut down 3rd party plugins. In principle it could (and should) be done on the view's "destroy". But if |
|
66c717a
to
f26475c
Compare
Updated with @paulovieira's comments, but I need to do three things
|
8bdc339
to
dd358e4
Compare
Alright. All updated and ready for review again. |
dd358e4
to
fa8f0a5
Compare
Oh, note to self...I need to add the right args here. |
triggerBeforeAttach: true, | ||
triggerAttach: true, | ||
|
||
_triggerAttach: function(views, prefix) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm maybe triggerMethodMany or pull the each up. You don't need the if if triggerMethodOn is smart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this with some clever _.union
code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revisiting this function again -
what I'd like to be able to do is write:
if (this.isAttached() && shouldTriggerAttach) {
this.triggerMany(this._displayedViews(), 'attach', this);
}
So, i realize that this is a lot of changes rolled up in one snippet:
- isAttached is discussed above
- shouldTriggerAttach is discussed above
- _displayedViews is discussed above
triggerMany
is a nice abstraction because it cleans up the loop
. Also, I don't like triggerAttach
because it is attach
specific. If we keep it I'd call it triggerMany
and pass in the full event name so that it can be re-used. w/r/t passing the view as the first event argument - i think that makes a lot of sense and we can do that with some concat action.
Having the region check for view.isDestroyed does two things: 1. It allows you to handle the error of a region.show without the region killing the currentView and breaking without recourse. 2. appending isDestroyed to a Backbone.View on region empty adds the same safety for not re-showing a removed backbone view. The extra return this; was removed to prevent jslint error for too many statements, and seemed unnecessary
4670252
to
12f1904
Compare
12f1904
to
a4835b1
Compare
Updated @jasonLaster.
I also added some good arguments for the trigger method: the view itself as the first argument, and the region as the second. This is ready for a final review and some final thumbz. Let's get this in...I still need to add |
@@ -87,8 +87,27 @@ Marionette.Region = Marionette.Object.extend({ | |||
this.triggerMethod('swapOut', this.currentView); | |||
} | |||
|
|||
// An array of views that we're about to display | |||
var attachedRegion = Marionette.isNodeAttached(this.el); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable name suggests that it should reference the "attached region" which is unclear.
I think a better name would be isRegionAttached
and i think that could be moved to a function (this.isAttached()
).
Awesome work @jmeas. Added lots of comments, but this guy is good and will get in soon |
@jmeas let's get this guy in. Then onDetatch |
Hey @jmeas, I just rebased master onto minor. mind doing a quick rebase and re-push. |
7124f10
to
e6c87af
Compare
Closing in favor of #2043. |
Adds
triggerAttach
andbeforeTriggerAttach
triggerMethods.This is the 3rd out of 3 PRs to get #1886 in.