Skip to content

Commit

Permalink
add a few more tests, improve readme on SmartPath
Browse files Browse the repository at this point in the history
  • Loading branch information
sandhawke committed Dec 28, 2018
1 parent 2da4397 commit 98be350
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ implementations:
The helper class KeyedSet.SmartPatch acts like an array of change
events, but it "cancels" events that would have no effect when
combined. It can be used to record change events and then replay them
more efficiently.
more efficiently, especially in cases where there are rapid temporary
changes which do not need to be propagated.

```js
const KeyedSet = require('keyed-set')
Expand All @@ -142,5 +143,9 @@ s.clear()
p.length // => 1 No need to remember the adds at all
```

Events can be de-queued in an appropriate order using p.shift(). New
events can safely be added between calls to p.shift(), which returns
`undefined` whenever there are no queued events.

[npm-image]: https://img.shields.io/npm/v/keyed-set.svg?style=flat-square
[npm-url]: https://npmjs.org/package/keyed-set
13 changes: 13 additions & 0 deletions test-smart-patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ test('shift', t => {
t.deepEqual(p.shift(), { type: 'clear' })
t.deepEqual(p.shift(), undefined)

s.addAll([1, 2, 3])
t.deepEqual(p.shift(), { type: 'add', key: '1', item: 1 })
t.deepEqual(p.shift(), { type: 'add', key: '2', item: 2 })
s.addAll([4, 5])
t.deepEqual(p.shift(), { type: 'add', key: '3', item: 3 })
t.deepEqual(p.shift(), { type: 'add', key: '4', item: 4 })
s.clear()
t.deepEqual(p.shift(), { type: 'clear' })
s.addAll([3, 4])
t.deepEqual(p.shift(), { type: 'add', key: '3', item: 3 })
t.deepEqual(p.shift(), { type: 'add', key: '4', item: 4 })
t.deepEqual(p.shift(), undefined)

t.end()
})

Expand Down

0 comments on commit 98be350

Please sign in to comment.