-
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
onBeforeAttach and onAttach for CollectionView child views (continued) #2481
onBeforeAttach and onAttach for CollectionView child views (continued) #2481
Conversation
Looks like Travis choked :/ |
restarting the choked travis :-) |
nice - @ianmstew... mind summarizing the discussion for |
Okay everyone, please weigh in on this. Region#show() if (attachedRegion && triggerBeforeAttach) {
displayedViews = this._displayedViews(view);
this._triggerAttach(displayedViews, 'before:');
}
this.attachHtml(view);
this.currentView = view;
if (attachedRegion && triggerAttach) {
displayedViews = this._displayedViews(view);
this._triggerAttach(displayedViews);
} CollectionView#_addChildView() - My preferred approach if (canTriggerAttach && this._triggerBeforeAttach) {
nestedViews = [view].concat(view._getNestedViews());
// Trigger before:attach after render to honor Region#show() lifecycle order.
view.once('render', _.partial(this._triggerMethodOnAll, nestedViews, 'before:attach'), this);
}
this.renderChildView(view, index);
if (canTriggerAttach && this._triggerAttach) {
nestedViews = [view].concat(view._getNestedViews());
this._triggerMethodOnAll(nestedViews, 'attach');
}
if (this._isShown && !this.isBuffering) {
Marionette.triggerMethodOn(view, 'show', view);
}
...
// render the child view
renderChildView: function(view, index) {
view.render();
this.attachHtml(this, view, index);
return view;
}, CollectionView#_addChildView - One alternative without "once render" this.renderChildView(view, index);
if (canTriggerAttach && this._triggerAttach) {
nestedViews = [view].concat(view._getNestedViews());
this._triggerMethodOnAll(nestedViews, 'attach');
}
if (this._isShown && !this.isBuffering) {
Marionette.triggerMethodOn(view, 'show', view);
}
...
// render the child view
renderChildView: function(view, index) {
var canTriggerAttach = this._isShown && !this.isBuffering && Marionette.isNodeAttached(this.el);
var nestedViews;
view.render();
if (canTriggerAttach && this._triggerBeforeAttach) {
nestedViews = [view].concat(view._getNestedViews());
// Trigger before:attach after render to honor Region#show() lifecycle order.
this._triggerMethodOnAll(nestedViews, 'before:attach');
}
this.attachHtml(this, view, index);
return view;
}, CollectionView#_addChildView - Second alternative without "once render" var triggerBeforeAttach = canTriggerAttach && this._triggerAttach;
this.renderChildView(view, index, triggerBeforeAttach);
if (canTriggerAttach && this._triggerAttach) {
nestedViews = [view].concat(view._getNestedViews());
this._triggerMethodOnAll(nestedViews, 'attach');
}
if (this._isShown && !this.isBuffering) {
Marionette.triggerMethodOn(view, 'show', view);
}
...
// render the child view
renderChildView: function(view, index, triggerBeforeAttach) {
view.render();
if (triggerBeforeAttach) {
this.triggerBeforeAttachOn(view);
}
this.attachHtml(this, view, index);
return view;
},
...
triggerBeforeAttachOn: function(view) {
nestedViews = [view].concat(view._getNestedViews());
// Trigger before:attach after render to honor Region#show() lifecycle order.
this._triggerMethodOnAll(nestedViews, 'before:attach');
} I prefer my approach for a few reasons:
I can see two issues:
I added a third option that solves some of the problems, but not all of them. I've thought a lot about this, but you all might see something I'm missing. Thoughts? |
All, this could be the final commit if you like the looks of my |
This is looking good. It's painful to see all of the duplication between addChildView and addEmptyView 😭 but obviously not the issue at hand. So one thing to consider. |
Yes, addEmptyView/addChildView is eye watering :( One of these passes through CollectionView we should refactor that. Hmm, adding "_" would simplify things. I would change it to I have no problem with this approach, and we can skip the |
Yep if this were for a minor release the _ would make me more nervous :-) |
As for moving this configuration to AbstractView, it's a bit complicated actually. All this code is to allow the CollectionView to behave like a Region only when it has already been shown by a Region, a precedent set by how the Speaking of refactoring, the huge logical interdependency between CollectionView and Region that I mentioned doesn't sit well with me, and I want to consider a better architecture for giving CollectionView region-like behavior without all this special case handling. |
Ahhhh next is the next major release ;) Got it. I was looking at the extinction of ItemView/LayoutView and wondering, ha. Since this is a bugfix I figured it would go out in a patch release, but no? |
Ah I see.. well that'd need to be a PR against 2.4.2 at the moment.. @jasonLaster ? thought on if this should be a patch or just added to next? Might affect the |
Hmm, I'd prefer to have it added as a patch because re-attaching an itemview on re-render is an important consideration. With that said, this is a big patch, so I could see the case for just doing it right for 3.0. @cmaher, @ahumphreys87 how do you feel as well? |
I'd quite like to see this in 2.4.2 if it isn't too far away, there a couple of fixes in that branch waiting for release already. If we do this are we commited to onDetach for 2.x? If so maybe wait for 3.0 |
Why would this commit us to onDetatch in 2.x? How about this, let's get this branch onto next and then do a separate PR for 2.4.2, would be nearly identical, just nonbreaking. |
@jasonLaster I agree. Rebasing onto 2.4.2 will eliminate some forward-thinking code, so I like the idea of keeping it then making a backwards-compatible version for 2.4.2. ( Okay, let's sum this up so we can ship.
Thumbs up? |
👍 thanks for consolidating |
👍 go go go :) On Monday, 13 April 2015, Jason Laster notifications@github.com wrote:
|
On it! |
43f2543
to
fddc990
Compare
Hey all, hopefully this is a wrap. A few notes:
Once this is merged I can cherry-pick onto 2.4.2. That will take some modification, but with the tests intact hopefully won't be too bad. |
👍 so pleased |
fddc990
to
6d0b181
Compare
Realized I could clean up |
6d0b181
to
9f3d861
Compare
👍 |
onBeforeAttach and onAttach for CollectionView child views (continued)
Great work Ian! |
Thanks, guys! |
no, thank you! |
Continuation of #2441, fixes #2209.
New feature of this PR:
Region#show()
'striggerBeforeAttach
andtriggerAttach
flags.Needs the following wrapup, probably 1-2 hours' work, will do in next day or so:
view.once('render'
to triggerbefore:attach
within_addChildView
andaddEmptyView
. See onBeforeAttach and onAttach for CollectionView child views #2441 (comment). @jasonLaster I wouldn't mind talking this one through more.triggerBeforeShow == false
triggerShow == false
before:attach