-
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
Rethink the way regions are created in View #3417
Comments
I completely agree with this. I don't think regions should do any selector work. I'm not convinced we'll want this in v4... but maybe. |
To much work as a breaking change? |
I think our major releases shouldn't require much app refactoring.. I think hopefully v4 can be |
Somehow related to this issue, here are some ideas to simplify the way regions are declared (not completely new I guess). See also #3497 for context. 1) "anonymous" regionsIn this scenario we would use a boolean attribute in the template to mark the elements that will be used as the regions' containers: <div>
...
<nav data-mr-region></nav>
...
<div data-mr-region></div>
</div> There would be no need to use 'regions' option anymore (at least for the anonymous regions): var ViewA = Mn.View.Extend({
template: ...
//regions: { // <-- not needed!
// ...
//}
}) The api would be same as in v3, except that the regions don't have a name anymore. We would use the respective index number instead: // code inside ViewA
this.getRegion(0).showView(new ViewB)
this.getRegion(1).showView(new ViewC)
// or
this.showChildView(0, new ViewB)
this.showChildView(1, new ViewC) This would be valid only for standard regions. For custom regions we would use the standard approach. The main use case for this new way of declaring regions would be for view with only 1 or 2 regions (which for me is quite common). Having to think of a region name everytime I need new one takes effort (plus adding it to the 'regions' option). 2) "automatic named" regionsIt's similar to the above, but for those cases where we actually want the region to have a name. I've seen other people proposing this. <div>
...
<nav data-mr-region="left"></nav>
...
<div data-mr-region="right"></div>
</div> As above, no need to use 'regions' option anymore: var ViewA = Mn.View.Extend({
template: ...
//regions: { // <-- not needed!
// ...
//}
}) Then we would use the current api. The region name is the value of the "data-mn-region" attribute. // code inside ViewA
this.getRegion('left').showView(new ViewB)
this.getRegion('right').showView(new ViewV)
// or
this.showChildView('left', new ViewB)
this.showChildView('right', new ViewC) |
I don't like non-named regions because different renders could produce different results. With named regions a more declarative API is very possible @JSteunou is already doing this with auto-region. I think we can make this easier to support as well through the current UI. I think the biggest improvements will come from having the view pass the dom element to the region instead of the region querying the DOM itself. And then finding a way to potentially reduce the need for instantiating the region until the first But yeah.. I think the job |
Can you explain better how can that happen?
Agree 100%. But those are separate issues. My itent here was just to reduce the boilerplate needed to add a new region. Currently we have to
But the important thing is just in 3). 1) and 2) are nothing but boilerplate that could be automated by marionette. |
<div data-mr-region></div>
{{#if isAdmin}}
<div class="admin-panel">
<div data-mr-region></div>
<div data-mr-region></div>
</div>
{{/if}}
<div data-mr-region></div> As far as the other stuff, I lean towards reducing the opinions of how this could be accomplished and making it easier for others to come up with implementations to make it easier. Maybe there is a best way to do this, but I could see some people wanting to declare regions and possibly even childviews inside their templates.. then I could also see just allowing people to use a selector instead of a named region in |
|
I think we can somewhat create regions on the fly, and I think the v5 plans allow for this with |
From #1971 & #3389 it seems that a good clean up for view's regions would be to create those only when needed / accessed.
What about stop create regions from within View constructor, but rather create each one when being accessed, from the getter? Also the
region.el
should be created from the view el, and not being looked up from someparentEl
option, unless theel
is already a node or a region without parent view. This would solve the missingregion.$el
case.The text was updated successfully, but these errors were encountered: