Skip to content

Instantly share code, notes, and snippets.

@ppcano
Created October 31, 2011 16:56
Show Gist options
  • Save ppcano/1327997 to your computer and use it in GitHub Desktop.
Save ppcano/1327997 to your computer and use it in GitHub Desktop.
View does not update the DOM when binded content is updated
require('sproutcore');
var set = SC.set;
var get = SC.get;
var max = 100
, i = 0
, content = [];
module("ScrollView test", {
setup: function() {
console.group(' - Setup for new test');
App = SC.Application.create({});
for(i=0; i< max; i++) {
content.push( SC.Object.create( { position: i, name: 'asdasdf' } ) );
}
SC.run(function() { // require for applying the binding
App.view = SC.CollectionView.create({
tagName: 'ul',
classNames: ['list-scroll-view'],
elementId: 'myid',
content: content,
itemViewClass: SC.View.extend({
template: SC.Handlebars.compile('{{content.position}} {{content.name}}')
})
});
});
SC.run(function() {
App.view.append();
});
},
teardown: function() {
content = [];
App.view.destroy();
App.destroy();
console.groupEnd();
}
});
test("should remove an item in DOM when removed an item from the content ", function() {
equals(SC.getPath('App.view.content').length, max, " there are items === max");
equals(App.view.$('li').length, max, " there are number of li === max");
SC.run(function() {
// HERE is the problem: _contentWill/DidChange won't be triggered
// use instead content.removeAt(1) --> sproutcore-runtime mutable array properties
content.pop();
});
equals(SC.getPath('App.view.content').length, max-1, " there are items === max-1");
equals(App.view.$('li').length, max-1, " there are number of li === max-1");
});
@ppcano
Copy link
Author

ppcano commented Oct 31, 2011

the fourth assert fails:

why won't the view update the DOM?

It seems that _contentWillChange and _contentDidChange won't be triggered on CollectionView.

Is that a RunLoop or CollectionView problem?

*** using bmp and SC20

@ppcano
Copy link
Author

ppcano commented Oct 31, 2011

Solved: problem because using JS array methods instead the ones ( insertAt, removedAt ) defined by SC.

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