Skip to content
Browse files

Changed so that row deletes now result in a history like this:

{
  ID: [null, ts4, source]
}
  • Loading branch information...
1 parent d7dedff commit aa7b0f03bc3fd91eca9d01c002012814178a1f2c @mbrevoort committed Apr 10, 2013
Showing with 17 additions and 26 deletions.
  1. +15 −12 doc.js
  2. +2 −14 test/rm.js
View
27 doc.js
@@ -162,10 +162,13 @@ Doc.prototype.applyUpdate = function (update, source) {
if (changes === null) {
// clean up the history
- changes = {}
for(var key in row.state) {
if(row.state.hasOwnProperty(key)) {
- changes[key] = null;
+ if(!hist[key] || order(hist[key], update) < 0) {
+ if(hist[key]) this.emit('_remove', hist[key])
+ hist[key] = [ null, update[1], update[2]]
+ emit = true
+ }
}
}
@@ -181,16 +184,16 @@ Doc.prototype.applyUpdate = function (update, source) {
delete this.rows[id]
this.emit('remove', row)
}
-
-
- for(var key in changes) {
- if(changes.hasOwnProperty(key)) {
- var value = changes[key]
- if(!hist[key] || order(hist[key], update) < 0) {
- if(hist[key]) this.emit('_remove', hist[key])
- hist[key] = update
- changed[key] = changes[key]
- emit = true
+ else {
+ for(var key in changes) {
+ if(changes.hasOwnProperty(key)) {
+ var value = changes[key]
+ if(!hist[key] || order(hist[key], update) < 0) {
+ if(hist[key]) this.emit('_remove', hist[key])
+ hist[key] = update
+ changed[key] = value
+ emit = true
+ }
}
}
}
View
16 test/rm.js
@@ -9,22 +9,10 @@ exports.test = function (t) {
var init = {id: 'taonihu', prop: 'key', type: 'thing'}
-
- // doc.on('create', function (row) {
- // //assert.deepEqual(row.toJSON(), init)
- // console.log(row);
- // doc.rm(row.id);
- // })
-
- // doc.on('row_update', function (update) {
- // console.log(doc)
- // assert(doc.rows[init.id] === undefined)
- // assert(set.get(init.id) === undefined)
-
- // })
-
doc.add(init)
doc.rm(init.id)
+ doc.rm(init.id) // test a double row delete
+ doc.rm('bogus') // test for non-existent
next(function () {
assert(doc.rows[init.id] === undefined)

0 comments on commit aa7b0f0

Please sign in to comment.
Something went wrong with that request. Please try again.