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

Move the setting of element to null after the childViews.replace()... Fixes issue #78. #80

Merged
merged 3 commits into from
Jul 14, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions packages/sproutcore-handlebars/tests/views/collection_view_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,51 @@ test("should render multiple, bound nested collections (#68)", function() {
equals(view.$('ul.inner:last > li').length, 3, "renders the second list with correct number of items");

});

test("should allow view objects to be swapped out without throwing an error (#78)", function() {
var view, dataset, secondDataset;

SC.run(function() {
TemplateTests.datasetController = SC.Object.create();

TemplateTests.ReportingView = SC.View.extend({
datasetBinding: 'TemplateTests.datasetController*dataset',
readyBinding: 'dataset.ready',
itemsBinding: 'dataset.items',
template: SC.Handlebars.compile("{{#if ready}}{{collection TemplateTests.CollectionView}}{{else}}Loading{{/if}}")
});

TemplateTests.CollectionView = SC.CollectionView.extend({
contentBinding: 'parentView.parentView.items',
tagName: 'ul',
template: SC.Handlebars.compile("{{content}}")
});

view = TemplateTests.ReportingView.create();
});

SC.run(function() {
view.appendTo('#qunit-fixture');
});

equals(view.$().text(), "Loading", "renders the loading text when the dataset is not ready");

SC.run(function() {
dataset = SC.Object.create({
ready: true,
items: [1,2,3]
});
TemplateTests.datasetController.set('dataset',dataset);
});

equals(view.$('ul > li').length, 3, "renders the collection with the correct number of items when the dataset is ready");

SC.run(function() {
secondDataset = SC.Object.create({ready: false});
TemplateTests.datasetController.set('dataset',secondDataset);
});

equals(view.$().text(), "Loading", "renders the loading text when the second dataset is not ready");

});

5 changes: 4 additions & 1 deletion packages/sproutcore-views/lib/views/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,6 @@ SC.View.states = {
rerender: function(view) {
var viewMeta = meta(this)['SC.View'], element = get(view, 'element');

set(view, 'element', null);
view.state = 'preRender';

var lengthBefore = viewMeta.lengthBeforeRender,
Expand All @@ -1181,6 +1180,10 @@ SC.View.states = {
childViews.replace(lengthBefore, lengthAfter - lengthBefore);
}

// Set element to null after the childViews.replace() call to prevent
// a call to $() from inside _scheduleInsertion triggering a rerender.
set(view, 'element', null);

view._insertElementLater(function() {
SC.$(element).replaceWith(get(this, 'element'));
});
Expand Down