UNPKG

blazepress

Version:

A rapid web application development platform for Node.js

51 lines (27 loc) 658 B
const EventEmitter = require( 'events' ).EventEmitter /** * @class * A Map which emits events on mutation */ class ActiveMap extends Map { constructor( ...args ) { super( ...args ) this.events = new EventEmitter; } set( ...args ) { Map.prototype.set.call( this, ...args ) this.events.emit( 'set', ...args ) } delete( ...args ) { Map.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 = ActiveMap