-
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 CollectionView to be populated with pre-rendered DOM #3135
Conversation
If you were to override `buildChildView` instantiating the childViews with an `el` then you can create a collectionView from pre-rendered DOM
CollectionView can’t be initially “rendered” because it does its initialization of many things on first render.
looks reasonable. need help with the test? |
sure thing. this branch is on the core, so you can commit right to it if ya want. |
I'll git to it sometime today. |
when a collection view is DOM * and it's not attached to the document ** should have _isAttached set to false * and it's attached to the document ** should have _isAttached set to true when rendering a childView * should not render childView twice
@@ -28,6 +28,34 @@ describe('collection view', function() { | |||
// Collection View Specs | |||
// --------------------- | |||
|
|||
describe('when a collection view is DOM', function() { | |||
beforeEach(function() { | |||
this.$fixtureEl = $('<div id="fixture-collectionview"></div>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we change the fixture to cater for when childViews are pre-rendered as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like
this.$fixtureEl = $('<div id="fixture-collectionview"><span id="el1">1</span></div>');
this.view1 = new this.ChildView({el: this.$fixtureEl.find('#el1')[0]});
then
this.collectionView.addChildView(this.view1, 0);
although I haven't tried that addChildView nor do I know if it will work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can also just be new this.ChildView({ el: '#el1' });
and I do think addChildView
would work work.
when a collection view is DOM * and it's not attached to the document ** should have a child view without `_isAttached` * and it's attached to the document ** should have a child view with `_isAttached` set to `true`
@paulfalgout @ahumphreys87 updated. |
Slightly related issue #2154 |
👍 |
2 similar comments
👍 |
👍 |
https://jsfiddle.net/t29dkss1/1/
I don't really know if this would be considered breaking.. I don't really think so..
This will need tests..thanks @rafdeAlso one point to note.. overriding
buildChildView
was easy.. however that same function is used to build the emptyView which is kind of unfortunate.. it means that when an emptyView is built we're making an empty model to pass to this function.. and when you override it, we'll have to first detect if the view being passed is the childView or the emptyView before doing something out of the ordinary with the el.