From bb2219b536c812f51644eccafc6fb22316688e9a Mon Sep 17 00:00:00 2001 From: Sean Zellmer Date: Wed, 15 Mar 2023 16:31:09 -0500 Subject: [PATCH] feat: Add `core-added` event when a core is added to autobase This allows one to react to new cores being added by `autobase-manager` to the underlying autobase. --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8e611e3..26bad2b 100644 --- a/index.js +++ b/index.js @@ -3,11 +3,13 @@ import c from 'compact-encoding' import b4a from 'b4a' import Hypercore from 'hypercore' import { difference } from './utils/set-operations.js' +import { EventEmitter } from 'events' const DEBUG = false -export class AutobaseManager { +export class AutobaseManager extends EventEmitter { constructor (base, allow, get, storage, opts = {}) { + super() this.base = base this.allow = allow this.get = get @@ -171,6 +173,7 @@ export class AutobaseManager { this._inputKeys.add(b4a.toString(core.key, 'hex')) await this.base.addInput(core) } + this.emit('core-added', core, destination) } }