-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Consider merging the events swapOut and swap (Marionette.Region) #1866
Comments
Thanks for the suggestion, @paulovieira! I think we need 2 events, though, when you consider things from the perspective of the views. As you pointed out, If we adopted your pattern, you'd have to do: // within myView
this.on('swap', function(newView, oldView) {
if (this === newView) {
// I'm being swapped in
} else {
// I'm being swapped out
}
} which is no good, I think. In v3, the names will be |
To clarify what @jmeas was saying, in the future we would like to be calling these triggerMethods on the view instead of the region where they would be much more useful, and in which case there should be two. However, I think the triggerMethods on the region could still be useful. In which case it does make sense to have a single triggerMethod. So I'm 👍 to this idea. |
I wasn't aware that these events should also be triggered on the views. I agree that I always see a region as the stage, and the views as blind actors (assume the stage can only have one actor at a given time). The actors don't know who was at the stage before them, nor who will come after them. Only the stage has that knowledge. So for the To wrap up, my choice would be something like:
|
I was wrong before; I wasn't aware we were only triggering it on the region. Agree w. you both 👍 |
This was added the region initially to support custom animations and to let the region be a bit more aware of what is going on inside of it. I think adding it on the view would be nice also, but there was a use case and rational behind why this was added to regions in the first place. |
I am still behind having two events. One to "clear" the stage and one to present a new "actor" on the stage. Lets look at the code 32116ff#diff-fda89a81760f4fc087909fd080d578c7R146 when a view is being swapped out the region now knows about it, this is really useful if you want to fade/move/do anything to the region or child. Here is an even better question why should a view be aware of other views being shown where the current view is? should the view even know it is a region? I don't think so and it seems like a leak of knowledge. The region should be aware of its children and what the children are doing. the children should not be aware of what potential new views are going to do... Some thoughts, again, I do not think these things were blindly added there was a rational. |
Makes sense, @samccone. This has nothing to do with animations since it's all synchronous, but you're right that there is a pretty big diff. between the two. I'm cool keeping it separate on the region as well. |
Indeed with the default region implementation it is. But this is really to help people doing custom regions :) |
Makes sense then to have two events on the region. We get more fine-grained events. The names would be more meaningful as So to sum it up, with the current names:
The only thing that remains confusing to me is the placement of the
However this.triggerMethod('swapOut', this.currentView); to be after this.attachHtml(view); |
Agreed @paulovieira! Because this has strayed from the original post, I'm going to close this issue and open a new one. Also, since this is all v3, I'm going to close everything & add them to #1796. Thanks for all your awesome work lately @paulovieira :) |
After reading the documentation (see #1859) and inspecting the code in the
show
method (Marionette.Region
), I don't see the advantage of triggering 2 different events on the region for the act of swapping a view:swap
andswapOut
.What if we had only a single
swap
event?That is:
before:swap
Triggered before the new view has replaced the old view within the Region. The new view is passed as the first argument. The old view is passed as the second argument.
Note: at the moment this event is triggered,
region.currentView
is still the old view.swap
Triggered when the new view has replaced the old view within the Region. The new view is passed as the first argument. The old view is passed as the second argument.
Note: at the moment this event is triggered,
region.currentView
is already the new view.This would make things more simple, no?
The text was updated successfully, but these errors were encountered: