-
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
Allow application with pre-generated html #3128
Comments
Just so I understand, the definition of |
Of course. It works fine if I instantiate it directly without the application and it's regions - but the application and it's region support is actually what I want. :) |
That sounds reasonable. I wonder if the best behaviour is to have the value of |
I think the way to accomplish this is to attach the view to the DOM element. That will mark that view as "rendered" then when you "show" it in the region it won't attempt to re-render it. |
oh actually I see the issue.. this is a recent bugfix.. it's not the view rendering.. it's the region empty on show.. ugh.. so.. somehow the region needs to know that the view it is being handled is currently a child of its |
Actually no it works as I described: While the region's el does get detached.. it gets reattached when the view is shown.. Is this what you're looking to accomplish? |
Indeed, setting the el does allow showView to be called without the existing dom being deleted. Is this something that should be documented? Or should it be possible to tell a region that it shouldn't empty the existing dom? I know I wasn't finding this solution from my trial and error and reading the docs + code, so maybe some documentation would be the solution? What do you think? |
Yeah I think documentation is in order.. not emptying the region could start all kinds of issues. |
This reads as if @dwt wants to treat the region as a collection view like. |
I didn't read that at all.. it seemed to me like there was already attached DOM in the region that he wanted to be part of a single view. setting the view to know about the attached DOM prior to showing it seems correct to me... now I believe you could just as easily do the same thing with a collectionView where the childViews were aware of the els they were responsible for... |
this is something i have touched upon when looking into an isomorphic plugin. Gets tricky mapping the view back to the data in order to do manipulation though - its possible though. We almost have a working prototype here: https://github.com/BedeGaming/orchestra/tree/iso, with a demo app here: https://github.com/BedeGaming/orchestra-wires |
can you explain, "view back to the data in order to do manipulation though" further? |
So imagine the server renders a table. You then want to sort the rows via some client side actions. To use CollectionView sort you would need the childViews to attach to a model. Kinda doing things in reverse |
Note the collectionView version of this requires #3135 |
How do I combine the technique shown in the jsfiddle if I want the view to replace the region's element? |
@jumika |
Hi, I'm quite new to Marionette and I'm struggling applying this concept to a pre-generated HTML and a little of view composition. I'm trying to create an Application with a region which contains a View with two regions, let's call them header and main. Here is a fiddle where I'm trying to demonstrate the concept but it's failing on missing DOM elements. Is such a scenario supported by Marionette? |
@oniric85 fiddle? |
Oh sorry @paulfalgout! Here it is https://jsfiddle.net/oniric85/sy6xsb7u/ |
@oniric85 2 things. Since things are already rendered, you can put your |
@paulfalgout You mean I should avoid calling app.getView().render() ? I've also tried to simply swap Marionette version in the fiddle but it does not seems to get rid of the error on its own. |
Ah yeah.. sorry.. avoid calling In fact I wouldn't use I think there's very little use-case for |
Thanks @paulfalgout, it's starting to make sense now :) |
So to resolve this I think there's this behavioral issue: And then we need to better document how this works in general. I suspect it needs to be it's own md file in addition to the bit we have in view lifecycle docs. I still fall on the side of making the path to this clearer programmatically, but aside from not doing #3243 we should document this clearly. @marionettejs/marionette-core ? Anyone want to take this on? |
https://jsfiddle.net/0wp0k7vs/6/ |
@rafde I think Now if you have a template to re-render the server rendered DOM it becomes a tad bit more complicated as you'll have to create children and other view stuff in both the |
closing as part of current work |
Allow application with pre-generated html
app.showView(someView, {dontTouchTheFrickingHTML: true})
Expected behavior
I want a way to tell the application (really the region) that it shouldn't empty the element it's about to attach a view to.
Actual behavior
It always empties it. Even with {preventDestroy: true} which seems to be the only relevant option that is available.
Environment
The text was updated successfully, but these errors were encountered: