Permalink
Browse files

Cleaned up Doc#delete to properly emit events, properly remove row fr…

…om set
  • Loading branch information...
1 parent 0a1deac commit d7dedffc57de7e8e97dab23a4171da7cb9d8ea85 @mbrevoort committed Apr 8, 2013
Showing with 11 additions and 7 deletions.
  1. +11 −7 doc.js
View
18 doc.js
@@ -89,11 +89,16 @@ Doc.prototype._add = function (id, source, change) {
this.rows[r.id] = r
function track (changes, source) {
+ //console.log(changes, source)
doc.localUpdate([r.id, changes])
}
r.on('preupdate', track)
+ r.on('remove', function () {
+ r.removeAllListeners('preupdate')
+ })
+
r._new = true
return r
}
@@ -156,26 +161,25 @@ Doc.prototype.applyUpdate = function (update, source) {
if (changes === null) {
- // clean up the history, this seems to work but seems like it should
- // be unnecessary
+ // clean up the history
changes = {}
for(var key in row.state) {
if(row.state.hasOwnProperty(key)) {
changes[key] = null;
}
}
- // remove from all sets
+ // remove from all sets that contain row
for (var setId in this.sets) {
var isSet = setId.indexOf(':') > 0
- if (isSet) {
- delete this.sets[setId].rows[row.id]
- }
+ var set = this.sets[setId]
+ var setContainsRow = isSet && set && set.get(row.id)
+ if (setContainsRow) set.rm(row)
}
// delete from the doc rows
delete this.rows[id]
- row.removeAllListeners('preupdate');
+ this.emit('remove', row)
}

0 comments on commit d7dedff

Please sign in to comment.