Skip to content

Instantly share code, notes, and snippets.

@thomaslang
Created September 1, 2009 19:06
Show Gist options
  • Save thomaslang/179311 to your computer and use it in GitHub Desktop.
Save thomaslang/179311 to your computer and use it in GitHub Desktop.
activeUnits: function(){
console.log('activeUnits');
var us = this.get('units');
if (us == this.previousUnits) return this.previousActiveUnits;
this.previousUnits = us;
var l = us.get('length');
var list = [];
var deleted = [];
var i, u, j, d;
for (i=0; i < l; i++) {
u = us.objectAt(i);
if ( list.indexOf(u) >= 0 ) {
// don't add this again!
}
else {
d = u.get('deletes');
if ( d ) deleted.push(d);
else list.push(u);
}
}
l = deleted.length;
for (i=0; i < l; i++) {
j = list.indexOf(deleted[i])
if (j>=0){
list.splice(j,1);
}
}
this.previousActiveUnits = list;
return list;
}.property(),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment