diff --git a/packages/dataverse/src/Box.ts b/packages/dataverse/src/Box.ts index 729897b..d92336b 100644 --- a/packages/dataverse/src/Box.ts +++ b/packages/dataverse/src/Box.ts @@ -1,6 +1,6 @@ import type {Prism} from './prism/Interface' import prism from './prism/prism' -import Emitter from './utils/Emitter' +import EventEmitter from './utils/EventEmitter' /** * Common interface for Box types. Boxes wrap a single value. @@ -39,7 +39,7 @@ export interface IBox { */ export default class Box implements IBox { private _publicPrism: Prism - private _emitter = new Emitter() + private _emitter = new EventEmitter() /** * @param _value - The initial value of the Box. @@ -50,8 +50,11 @@ export default class Box implements IBox { */ protected _value: V, ) { - const subscribe = (listener: (val: V) => void) => - this._emitter.tappable.tap(listener) + const subscribe = (listener: (val: V) => void) => { + this._emitter.addEventListener('change', listener) + return () => this._emitter.removeEventListener('change', listener) + } + const getValue = () => this._value this._publicPrism = prism(() => { return prism.source(subscribe, getValue) @@ -66,7 +69,7 @@ export default class Box implements IBox { set(v: V) { if (v === this._value) return this._value = v - this._emitter.emit(v) + this._emitter.emit('change', v) } /**