Finish event.

This commit is contained in:
Julien Fontanet 2015-05-19 15:25:30 +02:00
parent 3e7f1275d8
commit 7ddb57078c
2 changed files with 25 additions and 1 deletions

View File

@ -163,6 +163,17 @@ col.on('remove', (removed) => {
}) })
``` ```
**End of update**
> Emitted when all the update process is finished and all the update
> events has been emitted.
```javascript
col.on('finish', () => {
console.log('the collection has been updated')
})
```
### Iteration ### Iteration
```javascript ```javascript

View File

@ -248,6 +248,13 @@ export default class Collection extends EventEmitter {
return return
} }
const {_buffer: buffer} = this
// Due to deduplication there could be nothing in the buffer.
if (isEmpty(buffer)) {
return
}
const data = { const data = {
add: Object.create(null), add: Object.create(null),
remove: Object.create(null), remove: Object.create(null),
@ -255,7 +262,7 @@ export default class Collection extends EventEmitter {
} }
for (let key in this._buffer) { for (let key in this._buffer) {
data[this._buffer[key]][key] = this._items[key] data[buffer[key]][key] = this._items[key]
} }
forEach(data, (items, action) => { forEach(data, (items, action) => {
@ -264,6 +271,12 @@ export default class Collection extends EventEmitter {
} }
}) })
// Indicates the end of the update.
//
// This name has been chosen because it is used in Node writable
// streams when the data has been successfully committed.
this.emit('finish')
this._buffer = Object.create(null) this._buffer = Object.create(null)
} }
} }