Skip to content
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

Dynamic regions in LayoutView #2160

Closed
JSteunou opened this issue Dec 23, 2014 · 9 comments
Closed

Dynamic regions in LayoutView #2160

JSteunou opened this issue Dec 23, 2014 · 9 comments

Comments

@JSteunou
Copy link
Contributor

So I have a use case, so do @ianmstew and other folks on gitter.

Considering a sub app or module handling modals, I can have multiple modals. All the modal are in a LayoutView instance, the same for every modals.

In my controller I have dirty things like this

initialize: function(options) {
    this._regionsManager = new Marionette.RegionManager();

    // stuff...

},


_showModal: function(options) {
    var node = document.createElement('div'),
        view = new ModalView(options),
        regions = {};

    // add container to layout
    node.setAttribute('data-cid', view.cid);
    this._layout._ensureElement();
    this._layout.$el[0].appendChild(node);

    // set container as a region
    regions[view.cid] = '[data-cid="' + view.cid + '"]';
    this._regionsManager.addRegions(regions);

    // stuff...

}

My this._layout is just an instance of empty LayoutView. I should have put all the logic of dynamically adding node & regions inside, but eh... Thinking about it will chatting with Ian I was like: why this can be part of Marionette?

So, is it possible to add a kind of addDynamicRegion that would take a regionName and some options for the node like nodeName, className, etc... returning the node.

@samccone
Copy link
Member

This is a call for a new view class, something that does not need to be in core, but can be easily pulled in. I don't think this complexity belongs in the root layout base class.

@JSteunou
Copy link
Contributor Author

I dont know why but I thought the regionManager was private in LayoutView but it's not.

So yeah, a simple extend on LayoutView could do the job.

@ianmstew
Copy link
Member

@samccone A region that handles multiple views could achieve a similar goal. Since you wouldn't consider a LayoutView with dynamic regions for core, would you be more favorable toward a multi-region?

@ianmstew
Copy link
Member

I ask because, if core is more open to a multi-region than a dynamic layout, I'm sure @JSteunou and I could come up with something.

@samccone
Copy link
Member

Yeah The right way to explore this is going to be in a labs repo I think and we can play with the API outside of core... we can always talk about pulling it in after

@JSteunou
Copy link
Contributor Author

My need was not about multiple views in a single region, but I'm ok to drift on this subject. I can see mine is too specific and at the end I can reach it pretty easily.

@jmeas link to this https://github.com/joezimjs/MultiRegion maybe it can be useful

@jasonLaster
Copy link
Member

Create a Repo and we'll pull it into Labs!

@samccone
Copy link
Member

moving the work to here
https://github.com/MarionetteLabs/marionette.multiregion

@jasonLaster
Copy link
Member

Nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants