UNPKG

blazepress

Version:

A rapid web application development platform for Node.js

51 lines (27 loc) 660 B
const EventEmitter = require( 'events' ).EventEmitter /** * @class * A Set which emits events on mutation */ class ActiveSet extends Set { constructor( ...args ) { super( ...args ) this.events = new EventEmitter; } add( ...args ) { Set.prototype.add.call( this, ...args ) this.events.emit( 'added', ...args ) } delete( ...args ) { Set.prototype.delete.call( this, ...args ) this.events.emit( 'deleted', ...args ) } clear() { let entries = Array.from( this.entries() ) Set.prototype.clear.call( this ) for( let value of entries ) { this.events.emit( 'deleted', value ) } } } module.exports = ActiveSet