Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save courbije/efd17cdbfd5f532db06b to your computer and use it in GitHub Desktop.
Save courbije/efd17cdbfd5f532db06b to your computer and use it in GitHub Desktop.
// Init
App = SC.Application.create({
store: SC.Store.create().from(SC.Record.fixtures)
});
App.Contact = SC.Record.extend({
firstName: SC.Record.attr(String, { key: 'first_name' }),
lastName: SC.Record.attr(String, { key: 'last_name' }),
age: SC.Record.attr(Number),
ageSlow: function() {
function slow(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
};
slow(5); //busy wait 5ms
return this.get('age');
}.property('age').cacheable(),
});
var i = 0;
for (i= 0; i < 1000; i++) {
App.store.createRecord(App.Contact, { firstName: 'Florian'+i, lastName: 'Kugler'+i, age: i}, i);
}
// Test where we have the time to perform Query on 1 run loop
SC.run(function () {
ra = App.store.find(SC.Query.local(App.Contact, {
conditions: 'age > 100'
}));
console.trace("RecoardArray is in ReadClean state: " + (ra.status == SC.Record.READY_CLEAN));
array = ra.toArray();
console.trace("Array length (expected 899): "+ array.length);
});
// Test where we don't have the time to retrieve all data
// call it multiple time if needed
SC.run(function () {
ra = App.store.find(SC.Query.local(App.Contact, {
conditions: 'ageSlow > 100'
}));
console.trace("RecoardArray is in ReadClean state: " + (ra.status == SC.Record.READY_CLEAN));
array = ra.toArray();
console.trace("Array length (expected 899): "+ array.length);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment