import DerivationFromSource from './derivations/DerivationFromSource' ; import type { IDerivation } from './derivations/IDerivation' ; import Emitter from './utils/Emitter' ; export interface IBox < V > { set ( v ) : void ; get ( ) : V ; derivation : IDerivation < V > ; } export default class Box < V > implements IBox < V > { private _publicDerivation : IDerivation < V > ; private _emitter = new Emitter < V > ( ) ; constructor ( protected _value ) { this . _publicDerivation = new DerivationFromSource ( ( listener ) => this . _emitter . tappable . tap ( listener ) , this . get . bind ( this ) ) ; } set ( v ) { if ( v === this . _value ) return ; this . _value = v ; this . _emitter . emit ( v ) ; } get ( ) { return this . _value ; } get derivation ( ) { return this . _publicDerivation ; } }