

export class Observable<T>{
  value: T

  listeners: ((value:T)=>void)[]

  constructor(value?:T){
    this.value = value || null
    this.listeners = []
  }

  set(value: T){
    this.value = value
    for(let listener of this.listeners){
      listener(value)
    }
  }

  onChange(listener: (value:T)=>void):void{
    this.listeners.push(listener)
  }
  
  removeAllListeners(listener: (value:T)=>void):void{
    this.listeners = []
  }
}