@nbottarini/observable 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";class DefaultObservable{observers=new Set;handlers=new Map;subscribe(observer,handler){this.observers.add(observer),this.handlers.set(observer,handler.bind(observer))}hasObserver(observer){return this.observers.has(observer)}unsubscribe(observer){this.observers.delete(observer),this.handlers.delete(observer)}unsubscribeAll(){this.observers.clear(),this.handlers.clear()}async notify(value){let promises=[];for(const handler of this.handlers.values())promises.push(handler(value));await Promise.all(promises)}}function observable(){return new DefaultObservable}class CompositeObservable{sources;observers=new Set;handlers=new Map;onSourceEventRef=this.onSourceEvent.bind(this);constructor(sources){this.sources=sources}hasObserver(observer){return this.observers.has(observer)}async notify(value){throw new Error("CompositeObservable cannot be notified directly")}subscribe(observer,handler){const isFirstObserver=0===this.observers.size;this.observers.add(observer),this.handlers.set(observer,handler.bind(observer)),isFirstObserver&&this.attachToSources()}unsubscribe(observer){const hadObservers=this.observers.size>0;this.observers.delete(observer),this.handlers.delete(observer),hadObservers&&0===this.observers.size&&this.detachFromSources()}unsubscribeAll(){const hadObservers=this.observers.size>0;this.observers.clear(),this.handlers.clear(),hadObservers&&this.detachFromSources()}attachToSources(){for(const source of this.sources)source.subscribe(this,this.onSourceEventRef)}detachFromSources(){for(const source of this.sources)source.unsubscribe(this)}async onSourceEvent(value){let promises=[];for(const handler of this.handlers.values())promises.push(handler(value));await Promise.all(promises)}}function compositeObservable(...sources){return new CompositeObservable(sources)}class ObservableMutableValue{_value;changed=observable();constructor(initialValue){this._value=initialValue}subscribe(observer,handler){this.changed.subscribe(observer,handler)}hasObserver(observer){return this.changed.hasObserver(observer)}unsubscribe(observer){this.changed.unsubscribe(observer)}unsubscribeAll(){this.changed.unsubscribeAll()}async notify(value){return this.changed.notify(value)}get value(){return this._value}set value(newValue){this._value!==newValue&&(this._value=newValue,this.changed.notify(this._value))}}class ObservableComputedValue{computeFunc;internalChanged=observable();changed={subscribe:(o,h)=>this.subscribe(o,h),hasObserver:o=>this.hasObserver(o),unsubscribe:o=>this.unsubscribe(o),unsubscribeAll:()=>this.unsubscribeAll(),notify:v=>this.notify(v)};depsChanged;deps;onDepsChangedRef=this.onDepsChanged.bind(this);observerCount=0;hasValue=!1;cachedValue;constructor(computeFunc,...deps){this.computeFunc=computeFunc,this.deps=deps;const sources=deps.map((it=>it.changed));this.depsChanged=compositeObservable(...sources)}subscribe(observer,handler){const observerAlreadySubscribed=this.hasObserver(observer),isFirstObserver=0===this.observerCount;this.internalChanged.subscribe(observer,handler),observerAlreadySubscribed||this.observerCount++,isFirstObserver&&this.depsChanged.subscribe(this,this.onDepsChangedRef)}hasObserver(observer){return this.internalChanged.hasObserver(observer)}unsubscribe(observer){this.internalChanged.hasObserver(observer)&&(this.internalChanged.unsubscribe(observer),this.observerCount--,0===this.observerCount&&this.depsChanged.unsubscribe(this))}unsubscribeAll(){const hadObservers=this.observerCount>0;this.internalChanged.unsubscribeAll(),this.observerCount=0,hadObservers&&this.depsChanged.unsubscribe(this)}async notify(value){throw new Error("ComputedProperty cannot be notified directly")}get value(){return 0===this.observerCount?this.compute():(this.hasValue||(this.cachedValue=this.compute(),this.hasValue=!0),this.cachedValue)}compute(){const values=this.deps.map((d=>d.value));return this.computeFunc(...values)}onDepsChanged(){const newValue=this.compute();this.hasValue&&Object.is(this.cachedValue,newValue)||(this.cachedValue=newValue,this.hasValue=!0,this.internalChanged.notify(this.cachedValue))}}exports.CompositeObservable=CompositeObservable,exports.DefaultObservable=DefaultObservable,exports.ObservableComputedValue=ObservableComputedValue,exports.ObservableMutableValue=ObservableMutableValue,exports.compositeObservable=compositeObservable,exports.observable=observable,exports.observableComputed=function(computeFunc,...deps){return new ObservableComputedValue(computeFunc,...deps)},exports.observableValue=function(initialValue){return new ObservableMutableValue(initialValue)};
1
+ "use strict";class DefaultObservable{observers=new Set;handlers=new Map;subscribe(observer,handler){this.observers.add(observer),this.handlers.set(observer,handler.bind(observer))}hasObserver(observer){return this.observers.has(observer)}unsubscribe(observer){this.observers.delete(observer),this.handlers.delete(observer)}unsubscribeAll(){this.observers.clear(),this.handlers.clear()}async notify(value){let promises=[];for(const handler of this.handlers.values())promises.push(handler(value));await Promise.all(promises)}}function observable(){return new DefaultObservable}class CompositeObservable{sources;observers=new Set;handlers=new Map;onSourceEventRef=this.onSourceEvent.bind(this);constructor(sources){this.sources=sources}hasObserver(observer){return this.observers.has(observer)}async notify(value){throw new Error("CompositeObservable cannot be notified directly")}subscribe(observer,handler){const isFirstObserver=0===this.observers.size;this.observers.add(observer),this.handlers.set(observer,handler.bind(observer)),isFirstObserver&&this.attachToSources()}unsubscribe(observer){const hadObservers=this.observers.size>0;this.observers.delete(observer),this.handlers.delete(observer),hadObservers&&0===this.observers.size&&this.detachFromSources()}unsubscribeAll(){const hadObservers=this.observers.size>0;this.observers.clear(),this.handlers.clear(),hadObservers&&this.detachFromSources()}attachToSources(){for(const source of this.sources)source.subscribe(this,this.onSourceEventRef)}detachFromSources(){for(const source of this.sources)source.unsubscribe(this)}async onSourceEvent(value){let promises=[];for(const handler of this.handlers.values())promises.push(handler(value));await Promise.all(promises)}}function compositeObservable(...sources){return new CompositeObservable(sources)}class DerivedObservable{source;predicate;mapper;observers=new Set;handlers=new Map;onSourceEventRef=this.onSourceEvent.bind(this);constructor(source,predicate=(()=>!0),mapper){this.source=source,this.predicate=predicate,this.mapper=mapper}hasObserver(observer){return this.observers.has(observer)}async notify(_value){throw new Error("DerivedObservable cannot be notified directly")}subscribe(observer,handler){const isFirstObserver=0===this.observers.size;this.observers.add(observer),this.handlers.set(observer,handler.bind(observer)),isFirstObserver&&this.attachToSource()}unsubscribe(observer){const hadObservers=this.observers.size>0;this.observers.delete(observer),this.handlers.delete(observer),hadObservers&&0===this.observers.size&&this.detachFromSource()}unsubscribeAll(){const hadObservers=this.observers.size>0;this.observers.clear(),this.handlers.clear(),hadObservers&&this.detachFromSource()}attachToSource(){this.source.subscribe(this,this.onSourceEventRef)}detachFromSource(){this.source.unsubscribe(this)}async onSourceEvent(value){if(!this.predicate(value))return;const mapped=this.mapper?this.mapper(value):value;let promises=[];for(const handler of this.handlers.values())promises.push(handler(mapped));await Promise.all(promises)}}class ObservableMutableValue{_value;changed=observable();constructor(initialValue){this._value=initialValue}subscribe(observer,handler){this.changed.subscribe(observer,handler)}hasObserver(observer){return this.changed.hasObserver(observer)}unsubscribe(observer){this.changed.unsubscribe(observer)}unsubscribeAll(){this.changed.unsubscribeAll()}async notify(value){return this.changed.notify(value)}get value(){return this._value}set value(newValue){this._value!==newValue&&(this._value=newValue,this.changed.notify(this._value))}}class ObservableComputedValue{computeFunc;internalChanged=observable();changed={subscribe:(o,h)=>this.subscribe(o,h),hasObserver:o=>this.hasObserver(o),unsubscribe:o=>this.unsubscribe(o),unsubscribeAll:()=>this.unsubscribeAll(),notify:v=>this.notify(v)};depsChanged;deps;onDepsChangedRef=this.onDepsChanged.bind(this);observerCount=0;hasValue=!1;cachedValue;constructor(computeFunc,...deps){this.computeFunc=computeFunc,this.deps=deps;const sources=deps.map((it=>it.changed));this.depsChanged=compositeObservable(...sources)}subscribe(observer,handler){const observerAlreadySubscribed=this.hasObserver(observer),isFirstObserver=0===this.observerCount;this.internalChanged.subscribe(observer,handler),observerAlreadySubscribed||this.observerCount++,isFirstObserver&&this.depsChanged.subscribe(this,this.onDepsChangedRef)}hasObserver(observer){return this.internalChanged.hasObserver(observer)}unsubscribe(observer){this.internalChanged.hasObserver(observer)&&(this.internalChanged.unsubscribe(observer),this.observerCount--,0===this.observerCount&&this.depsChanged.unsubscribe(this))}unsubscribeAll(){const hadObservers=this.observerCount>0;this.internalChanged.unsubscribeAll(),this.observerCount=0,hadObservers&&this.depsChanged.unsubscribe(this)}async notify(value){throw new Error("ComputedProperty cannot be notified directly")}get value(){return 0===this.observerCount?this.compute():(this.hasValue||(this.cachedValue=this.compute(),this.hasValue=!0),this.cachedValue)}compute(){const values=this.deps.map((d=>d.value));return this.computeFunc(...values)}onDepsChanged(){const newValue=this.compute();this.hasValue&&Object.is(this.cachedValue,newValue)||(this.cachedValue=newValue,this.hasValue=!0,this.internalChanged.notify(this.cachedValue))}}exports.CompositeObservable=CompositeObservable,exports.DefaultObservable=DefaultObservable,exports.DerivedObservable=DerivedObservable,exports.ObservableComputedValue=ObservableComputedValue,exports.ObservableMutableValue=ObservableMutableValue,exports.compositeObservable=compositeObservable,exports.derivedObservable=function(source,predicate,mapper){return new DerivedObservable(source,predicate,mapper)},exports.observable=observable,exports.observableComputed=function(computeFunc,...deps){return new ObservableComputedValue(computeFunc,...deps)},exports.observableValue=function(initialValue){return new ObservableMutableValue(initialValue)};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/DefaultObservable.ts","../../src/CompositeObservable.ts","../../src/ObservableMutableValue.ts","../../src/ObservableComputedValue.ts"],"sourcesContent":["import { Observable, ObserverFunc } from './Observable'\n\nexport class DefaultObservable<T = void> implements Observable<T> {\n private observers: Set<object> = new Set()\n private handlers: Map<object, ObserverFunc<T>> = new Map()\n\n subscribe(observer: object, handler: ObserverFunc<T>) {\n this.observers.add(observer)\n this.handlers.set(observer, handler.bind(observer))\n }\n\n hasObserver(observer: object) {\n return this.observers.has(observer)\n }\n\n unsubscribe(observer: object) {\n this.observers.delete(observer)\n this.handlers.delete(observer)\n }\n\n unsubscribeAll() {\n this.observers.clear()\n this.handlers.clear()\n }\n\n async notify(value?: T) {\n let promises = []\n for (const handler of this.handlers.values()) {\n promises.push(handler(value))\n }\n await Promise.all(promises)\n }\n}\n\nexport function observable<T = void>(): Observable<T> {\n return new DefaultObservable<T>()\n}\n","import { Observable, ObserverFunc } from './Observable'\n\ntype EventOf<O> = O extends Observable<infer T> ? T : never\n\nexport class CompositeObservable<Sources extends readonly Observable<any>[]> implements Observable<EventOf<Sources[number]>> {\n private observers = new Set<object>()\n private handlers: Map<object, ObserverFunc<EventOf<Sources[number]>>> = new Map()\n private onSourceEventRef = this.onSourceEvent.bind(this)\n\n constructor(private readonly sources: Sources) {\n }\n\n hasObserver(observer: object): boolean {\n return this.observers.has(observer)\n }\n\n async notify(value?: EventOf<Sources[number]>) {\n throw new Error('CompositeObservable cannot be notified directly')\n }\n\n subscribe(observer: object, handler: ObserverFunc<EventOf<Sources[number]>>): void {\n const isFirstObserver = this.observers.size === 0\n this.observers.add(observer)\n this.handlers.set(observer, handler.bind(observer))\n\n if (isFirstObserver) this.attachToSources()\n }\n\n unsubscribe(observer: object): void {\n const hadObservers = this.observers.size > 0\n this.observers.delete(observer)\n this.handlers.delete(observer)\n\n if (hadObservers && this.observers.size === 0) this.detachFromSources()\n }\n\n unsubscribeAll(): void {\n const hadObservers = this.observers.size > 0\n this.observers.clear()\n this.handlers.clear()\n if (hadObservers ) this.detachFromSources()\n }\n\n private attachToSources() {\n for (const source of this.sources) {\n source.subscribe(this, this.onSourceEventRef)\n }\n }\n\n private detachFromSources() {\n for (const source of this.sources) {\n source.unsubscribe(this)\n }\n }\n\n private async onSourceEvent(value?: EventOf<Sources[number]>) {\n let promises = []\n for (const handler of this.handlers.values()) {\n promises.push(handler(value))\n }\n await Promise.all(promises)\n }\n}\n\nexport function compositeObservable<Sources extends readonly Observable<any>[]>(...sources: Sources) {\n return new CompositeObservable(sources)\n}\n","import { observable } from './DefaultObservable'\nimport { ObserverFunc } from './Observable'\nimport { ObservableValue } from './ObservableValue'\n\nexport class ObservableMutableValue<T> implements ObservableValue<T> {\n private _value: T\n readonly changed = observable<T>()\n\n constructor(initialValue: T) {\n this._value = initialValue\n }\n\n subscribe(observer: object, handler: ObserverFunc<T>) {\n this.changed.subscribe(observer, handler)\n }\n hasObserver(observer: object): boolean {\n return this.changed.hasObserver(observer)\n }\n unsubscribe(observer: object) {\n this.changed.unsubscribe(observer)\n }\n unsubscribeAll() {\n this.changed.unsubscribeAll()\n }\n\n async notify(value?: T): Promise<void> {\n return this.changed.notify(value)\n }\n\n get value(): T {\n return this._value\n }\n\n set value(newValue: T) {\n if (this._value === newValue) return\n this._value = newValue\n this.changed.notify(this._value)\n }\n}\n\nexport function observableValue<T>(initialValue: T): ObservableMutableValue<T> {\n return new ObservableMutableValue<T>(initialValue)\n}\n","import { ObservableValue } from './ObservableValue'\nimport { Observable, ObserverFunc } from './Observable'\nimport { compositeObservable } from './CompositeObservable'\nimport { observable } from './DefaultObservable'\n\ntype ValueOf<P> = P extends ObservableValue<infer T> ? T : never\n\nexport class ObservableComputedValue<Deps extends readonly ObservableValue<any>[], T> implements ObservableValue<T> {\n private readonly internalChanged = observable<T>()\n readonly changed: Observable<T> = {\n subscribe: (o, h) => this.subscribe(o, h),\n hasObserver: (o) => this.hasObserver(o),\n unsubscribe: (o) => this.unsubscribe(o),\n unsubscribeAll: () => this.unsubscribeAll(),\n notify: (v) => this.notify(v),\n }\n private readonly depsChanged: Observable<any>\n private readonly deps: Deps\n private readonly onDepsChangedRef = this.onDepsChanged.bind(this)\n private observerCount = 0\n private hasValue = false\n private cachedValue!: T\n\n constructor(private readonly computeFunc: (...values: { [K in keyof Deps]: ValueOf<Deps[K]> }) => T, ...deps: Deps) {\n this.deps = deps\n const sources = deps.map(it => it.changed)\n this.depsChanged = compositeObservable(...sources)\n }\n\n subscribe(observer: object, handler: ObserverFunc<any>) {\n const observerAlreadySubscribed = this.hasObserver(observer)\n const isFirstObserver = this.observerCount === 0\n this.internalChanged.subscribe(observer, handler)\n if (!observerAlreadySubscribed) {\n this.observerCount++\n }\n if (isFirstObserver) this.depsChanged.subscribe(this, this.onDepsChangedRef)\n }\n\n hasObserver(observer: object): boolean {\n return this.internalChanged.hasObserver(observer)\n }\n\n unsubscribe(observer: object) {\n if (!this.internalChanged.hasObserver(observer)) return\n\n this.internalChanged.unsubscribe(observer)\n this.observerCount--\n\n if (this.observerCount === 0) this.depsChanged.unsubscribe(this)\n }\n\n unsubscribeAll() {\n const hadObservers = this.observerCount > 0\n this.internalChanged.unsubscribeAll()\n this.observerCount = 0\n if (hadObservers) this.depsChanged.unsubscribe(this)\n }\n\n async notify(value?: any): Promise<void> {\n throw new Error('ComputedProperty cannot be notified directly')\n }\n\n get value(): T {\n // When there are no observers we must recompute on each call because we aren't watching dep changes\n if (this.observerCount === 0) return this.compute()\n\n if (!this.hasValue) {\n this.cachedValue = this.compute()\n this.hasValue = true\n }\n return this.cachedValue\n }\n\n private compute(): T {\n const values = this.deps.map(d => d.value) as { [K in keyof Deps]: ValueOf<Deps[K]> }\n return this.computeFunc(...values)\n }\n\n private onDepsChanged() {\n const newValue = this.compute()\n\n if (!this.hasValue || !Object.is(this.cachedValue, newValue)) {\n this.cachedValue = newValue\n this.hasValue = true\n this.internalChanged.notify(this.cachedValue)\n }\n }\n}\n\nexport function observableComputed<\n Deps extends readonly ObservableValue<any>[],\n T,\n>(computeFunc: (...values: { [K in keyof Deps]: ValueOf<Deps[K]> }) => T, ...deps: Deps) {\n return new ObservableComputedValue(computeFunc, ...deps)\n}\n"],"names":["DefaultObservable","observers","Set","handlers","Map","subscribe","observer","handler","this","add","set","bind","hasObserver","has","unsubscribe","delete","unsubscribeAll","clear","notify","value","promises","values","push","Promise","all","observable","CompositeObservable","sources","onSourceEventRef","onSourceEvent","constructor","Error","isFirstObserver","size","attachToSources","hadObservers","detachFromSources","source","compositeObservable","ObservableMutableValue","_value","changed","initialValue","newValue","ObservableComputedValue","computeFunc","internalChanged","o","h","v","depsChanged","deps","onDepsChangedRef","onDepsChanged","observerCount","hasValue","cachedValue","map","it","observerAlreadySubscribed","compute","d","Object","is"],"mappings":"mBAEaA,kBACDC,UAAyB,IAAIC,IAC7BC,SAAyC,IAAIC,IAErD,SAAAC,CAAUC,SAAkBC,SACxBC,KAAKP,UAAUQ,IAAIH,UACnBE,KAAKL,SAASO,IAAIJ,SAAUC,QAAQI,KAAKL,UAC5C,CAED,WAAAM,CAAYN,UACR,OAAOE,KAAKP,UAAUY,IAAIP,SAC7B,CAED,WAAAQ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,wBAAwBC,eAAgBM,KACvD,0BDvDM,SAA6BT,cAC/B,OAAO,IAAIH,uBAA0BG,aACzC"}
1
+ {"version":3,"file":"index.js","sources":["../../src/DefaultObservable.ts","../../src/CompositeObservable.ts","../../src/DerivedObservable.ts","../../src/ObservableMutableValue.ts","../../src/ObservableComputedValue.ts"],"sourcesContent":["import { Observable, ObserverFunc } from './Observable'\n\nexport class DefaultObservable<T = void> implements Observable<T> {\n private observers: Set<object> = new Set()\n private handlers: Map<object, ObserverFunc<T>> = new Map()\n\n subscribe(observer: object, handler: ObserverFunc<T>) {\n this.observers.add(observer)\n this.handlers.set(observer, handler.bind(observer))\n }\n\n hasObserver(observer: object) {\n return this.observers.has(observer)\n }\n\n unsubscribe(observer: object) {\n this.observers.delete(observer)\n this.handlers.delete(observer)\n }\n\n unsubscribeAll() {\n this.observers.clear()\n this.handlers.clear()\n }\n\n async notify(value?: T) {\n let promises = []\n for (const handler of this.handlers.values()) {\n promises.push(handler(value))\n }\n await Promise.all(promises)\n }\n}\n\nexport function observable<T = void>(): Observable<T> {\n return new DefaultObservable<T>()\n}\n","import { Observable, ObserverFunc } from './Observable'\n\ntype EventOf<O> = O extends Observable<infer T> ? T : never\n\nexport class CompositeObservable<Sources extends readonly Observable<any>[]> implements Observable<EventOf<Sources[number]>> {\n private observers = new Set<object>()\n private handlers: Map<object, ObserverFunc<EventOf<Sources[number]>>> = new Map()\n private onSourceEventRef = this.onSourceEvent.bind(this)\n\n constructor(private readonly sources: Sources) {\n }\n\n hasObserver(observer: object): boolean {\n return this.observers.has(observer)\n }\n\n async notify(value?: EventOf<Sources[number]>) {\n throw new Error('CompositeObservable cannot be notified directly')\n }\n\n subscribe(observer: object, handler: ObserverFunc<EventOf<Sources[number]>>): void {\n const isFirstObserver = this.observers.size === 0\n this.observers.add(observer)\n this.handlers.set(observer, handler.bind(observer))\n\n if (isFirstObserver) this.attachToSources()\n }\n\n unsubscribe(observer: object): void {\n const hadObservers = this.observers.size > 0\n this.observers.delete(observer)\n this.handlers.delete(observer)\n\n if (hadObservers && this.observers.size === 0) this.detachFromSources()\n }\n\n unsubscribeAll(): void {\n const hadObservers = this.observers.size > 0\n this.observers.clear()\n this.handlers.clear()\n if (hadObservers ) this.detachFromSources()\n }\n\n private attachToSources() {\n for (const source of this.sources) {\n source.subscribe(this, this.onSourceEventRef)\n }\n }\n\n private detachFromSources() {\n for (const source of this.sources) {\n source.unsubscribe(this)\n }\n }\n\n private async onSourceEvent(value?: EventOf<Sources[number]>) {\n let promises = []\n for (const handler of this.handlers.values()) {\n promises.push(handler(value))\n }\n await Promise.all(promises)\n }\n}\n\nexport function compositeObservable<Sources extends readonly Observable<any>[]>(...sources: Sources) {\n return new CompositeObservable(sources)\n}\n","import { Observable, ObserverFunc } from './Observable'\n\ntype Mapper<S, T> = (value?: S) => T\ntype Predicate<S> = (value?: S) => boolean\n\nexport class DerivedObservable<S, T = S> implements Observable<T> {\n private observers = new Set<object>()\n private handlers: Map<object, ObserverFunc<T>> = new Map()\n private onSourceEventRef = this.onSourceEvent.bind(this)\n\n constructor(\n private readonly source: Observable<S>,\n private readonly predicate: Predicate<S> = () => true,\n private readonly mapper?: Mapper<S, T>,\n ) {}\n\n hasObserver(observer: object): boolean {\n return this.observers.has(observer)\n }\n\n async notify(_value?: T) {\n throw new Error('DerivedObservable cannot be notified directly')\n }\n\n subscribe(observer: object, handler: ObserverFunc<T>): void {\n const isFirstObserver = this.observers.size === 0\n\n this.observers.add(observer)\n this.handlers.set(observer, handler.bind(observer))\n\n if (isFirstObserver) this.attachToSource()\n }\n\n unsubscribe(observer: object): void {\n const hadObservers = this.observers.size > 0\n\n this.observers.delete(observer)\n this.handlers.delete(observer)\n\n if (hadObservers && this.observers.size === 0) this.detachFromSource()\n }\n\n unsubscribeAll(): void {\n const hadObservers = this.observers.size > 0\n this.observers.clear()\n this.handlers.clear()\n if (hadObservers) this.detachFromSource()\n }\n\n private attachToSource() {\n this.source.subscribe(this, this.onSourceEventRef)\n }\n\n private detachFromSource() {\n this.source.unsubscribe(this)\n }\n\n private async onSourceEvent(value?: S) {\n if (!this.predicate(value)) return\n\n const mapped = this.mapper ? this.mapper(value) : (value as unknown as T)\n\n let promises = []\n for (const handler of this.handlers.values()) {\n promises.push(handler(mapped))\n }\n await Promise.all(promises)\n }\n}\n\nexport function derivedObservable<S, T = S>(\n source: Observable<S>,\n predicate: Predicate<S>,\n mapper?: Mapper<S, T>,\n) {\n return new DerivedObservable<S, T>(source, predicate, mapper)\n}\n","import { observable } from './DefaultObservable'\nimport { ObserverFunc } from './Observable'\nimport { ObservableValue } from './ObservableValue'\n\nexport class ObservableMutableValue<T> implements ObservableValue<T> {\n private _value: T\n readonly changed = observable<T>()\n\n constructor(initialValue: T) {\n this._value = initialValue\n }\n\n subscribe(observer: object, handler: ObserverFunc<T>) {\n this.changed.subscribe(observer, handler)\n }\n hasObserver(observer: object): boolean {\n return this.changed.hasObserver(observer)\n }\n unsubscribe(observer: object) {\n this.changed.unsubscribe(observer)\n }\n unsubscribeAll() {\n this.changed.unsubscribeAll()\n }\n\n async notify(value?: T): Promise<void> {\n return this.changed.notify(value)\n }\n\n get value(): T {\n return this._value\n }\n\n set value(newValue: T) {\n if (this._value === newValue) return\n this._value = newValue\n this.changed.notify(this._value)\n }\n}\n\nexport function observableValue<T>(initialValue: T): ObservableMutableValue<T> {\n return new ObservableMutableValue<T>(initialValue)\n}\n","import { ObservableValue } from './ObservableValue'\nimport { Observable, ObserverFunc } from './Observable'\nimport { compositeObservable } from './CompositeObservable'\nimport { observable } from './DefaultObservable'\n\ntype ValueOf<P> = P extends ObservableValue<infer T> ? T : never\n\nexport class ObservableComputedValue<Deps extends readonly ObservableValue<any>[], T> implements ObservableValue<T> {\n private readonly internalChanged = observable<T>()\n readonly changed: Observable<T> = {\n subscribe: (o, h) => this.subscribe(o, h),\n hasObserver: (o) => this.hasObserver(o),\n unsubscribe: (o) => this.unsubscribe(o),\n unsubscribeAll: () => this.unsubscribeAll(),\n notify: (v) => this.notify(v),\n }\n private readonly depsChanged: Observable<any>\n private readonly deps: Deps\n private readonly onDepsChangedRef = this.onDepsChanged.bind(this)\n private observerCount = 0\n private hasValue = false\n private cachedValue!: T\n\n constructor(private readonly computeFunc: (...values: { [K in keyof Deps]: ValueOf<Deps[K]> }) => T, ...deps: Deps) {\n this.deps = deps\n const sources = deps.map(it => it.changed)\n this.depsChanged = compositeObservable(...sources)\n }\n\n subscribe(observer: object, handler: ObserverFunc<any>) {\n const observerAlreadySubscribed = this.hasObserver(observer)\n const isFirstObserver = this.observerCount === 0\n this.internalChanged.subscribe(observer, handler)\n if (!observerAlreadySubscribed) {\n this.observerCount++\n }\n if (isFirstObserver) this.depsChanged.subscribe(this, this.onDepsChangedRef)\n }\n\n hasObserver(observer: object): boolean {\n return this.internalChanged.hasObserver(observer)\n }\n\n unsubscribe(observer: object) {\n if (!this.internalChanged.hasObserver(observer)) return\n\n this.internalChanged.unsubscribe(observer)\n this.observerCount--\n\n if (this.observerCount === 0) this.depsChanged.unsubscribe(this)\n }\n\n unsubscribeAll() {\n const hadObservers = this.observerCount > 0\n this.internalChanged.unsubscribeAll()\n this.observerCount = 0\n if (hadObservers) this.depsChanged.unsubscribe(this)\n }\n\n async notify(value?: any): Promise<void> {\n throw new Error('ComputedProperty cannot be notified directly')\n }\n\n get value(): T {\n // When there are no observers we must recompute on each call because we aren't watching dep changes\n if (this.observerCount === 0) return this.compute()\n\n if (!this.hasValue) {\n this.cachedValue = this.compute()\n this.hasValue = true\n }\n return this.cachedValue\n }\n\n private compute(): T {\n const values = this.deps.map(d => d.value) as { [K in keyof Deps]: ValueOf<Deps[K]> }\n return this.computeFunc(...values)\n }\n\n private onDepsChanged() {\n const newValue = this.compute()\n\n if (!this.hasValue || !Object.is(this.cachedValue, newValue)) {\n this.cachedValue = newValue\n this.hasValue = true\n this.internalChanged.notify(this.cachedValue)\n }\n }\n}\n\nexport function observableComputed<\n Deps extends readonly ObservableValue<any>[],\n T,\n>(computeFunc: (...values: { [K in keyof Deps]: ValueOf<Deps[K]> }) => T, ...deps: Deps) {\n return new ObservableComputedValue(computeFunc, ...deps)\n}\n"],"names":["DefaultObservable","observers","Set","handlers","Map","subscribe","observer","handler","this","add","set","bind","hasObserver","has","unsubscribe","delete","unsubscribeAll","clear","notify","value","promises","values","push","Promise","all","observable","CompositeObservable","sources","onSourceEventRef","onSourceEvent","constructor","Error","isFirstObserver","size","attachToSources","hadObservers","detachFromSources","source","compositeObservable","DerivedObservable","predicate","mapper","_value","attachToSource","detachFromSource","mapped","ObservableMutableValue","changed","initialValue","newValue","ObservableComputedValue","computeFunc","internalChanged","o","h","v","depsChanged","deps","onDepsChangedRef","onDepsChanged","observerCount","hasValue","cachedValue","map","it","observerAlreadySubscribed","compute","d","Object","is"],"mappings":"mBAEaA,kBACDC,UAAyB,IAAIC,IAC7BC,SAAyC,IAAIC,IAErD,SAAAC,CAAUC,SAAkBC,SACxBC,KAAKP,UAAUQ,IAAIH,UACnBE,KAAKL,SAASO,IAAIJ,SAAUC,QAAQI,KAAKL,UAC5C,CAED,WAAAM,CAAYN,UACR,OAAOE,KAAKP,UAAUY,IAAIP,SAC7B,CAED,WAAAQ,CAAYR,UACRE,KAAKP,UAAUc,OAAOT,UACtBE,KAAKL,SAASY,OAAOT,SACxB,CAED,cAAAU,GACIR,KAAKP,UAAUgB,QACfT,KAAKL,SAASc,OACjB,CAED,YAAMC,CAAOC,OACT,IAAIC,SAAW,GACf,IAAK,MAAMb,WAAWC,KAAKL,SAASkB,SAChCD,SAASE,KAAKf,QAAQY,cAEpBI,QAAQC,IAAIJ,SACrB,WAGWK,aACZ,OAAO,IAAIzB,iBACf,OChCa0B,oBAKoBC,QAJrB1B,UAAY,IAAIC,IAChBC,SAAgE,IAAIC,IACpEwB,iBAAmBpB,KAAKqB,cAAclB,KAAKH,MAEnD,WAAAsB,CAA6BH,SAAAnB,KAAOmB,QAAPA,OAC5B,CAED,WAAAf,CAAYN,UACR,OAAOE,KAAKP,UAAUY,IAAI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eAAqBpD,KAAKgD,YAAY1C,YAAYN,MAC9D,CAED,cAAAQ,GACI,MAAMmB,aAAe3B,KAAKoD,cAAgB,EAC1CpD,KAAK4C,gBAAgBpC,iBACrBR,KAAKoD,cAAgB,EACjBzB,cAAc3B,KAAKgD,YAAY1C,YAAYN,KAClD,CAED,YAAMU,CAAOC,OACT,MAAM,IAAIY,MAAM,+CACnB,CAED,SAAIZ,GAEA,OAA2B,IAAvBX,KAAKoD,cAA4BpD,KAAK0D,WAErC1D,KAAKqD,WACNrD,KAAKsD,YAActD,KAAK0D,UACxB1D,KAAKqD,UAAW,GAEbrD,KAAKsD,YACf,CAEO,OAAAI,GACJ,MAAM7C,OAASb,KAAKiD,KAAKM,KAAII,GAAKA,EAAEhD,QACpC,OAAOX,KAAK2C,eAAe9B,OAC9B,CAEO,aAAAsC,GACJ,MAAMV,SAAWzC,KAAK0D,UAEjB1D,KAAKqD,UAAaO,OAAOC,GAAG7D,KAAKsD,YAAab,YAC/CzC,KAAKsD,YAAcb,SACnBzC,KAAKqD,UAAW,EAChBrD,KAAK4C,gBAAgBlC,OAAOV,KAAKsD,aAExC,2UFhBDzB,OACAG,UACAC,QAEA,OAAO,IAAIF,kBAAwBF,OAAQG,UAAWC,OAC1D,oEEiBEU,eAA2EM,MACzE,OAAO,IAAIP,wBAAwBC,eAAgBM,KACvD,0BDvDM,SAA6BT,cAC/B,OAAO,IAAIF,uBAA0BE,aACzC"}
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- class DefaultObservable{observers=new Set;handlers=new Map;subscribe(observer,handler){this.observers.add(observer),this.handlers.set(observer,handler.bind(observer))}hasObserver(observer){return this.observers.has(observer)}unsubscribe(observer){this.observers.delete(observer),this.handlers.delete(observer)}unsubscribeAll(){this.observers.clear(),this.handlers.clear()}async notify(value){let promises=[];for(const handler of this.handlers.values())promises.push(handler(value));await Promise.all(promises)}}function observable(){return new DefaultObservable}class CompositeObservable{sources;observers=new Set;handlers=new Map;onSourceEventRef=this.onSourceEvent.bind(this);constructor(sources){this.sources=sources}hasObserver(observer){return this.observers.has(observer)}async notify(value){throw new Error("CompositeObservable cannot be notified directly")}subscribe(observer,handler){const isFirstObserver=0===this.observers.size;this.observers.add(observer),this.handlers.set(observer,handler.bind(observer)),isFirstObserver&&this.attachToSources()}unsubscribe(observer){const hadObservers=this.observers.size>0;this.observers.delete(observer),this.handlers.delete(observer),hadObservers&&0===this.observers.size&&this.detachFromSources()}unsubscribeAll(){const hadObservers=this.observers.size>0;this.observers.clear(),this.handlers.clear(),hadObservers&&this.detachFromSources()}attachToSources(){for(const source of this.sources)source.subscribe(this,this.onSourceEventRef)}detachFromSources(){for(const source of this.sources)source.unsubscribe(this)}async onSourceEvent(value){let promises=[];for(const handler of this.handlers.values())promises.push(handler(value));await Promise.all(promises)}}function compositeObservable(...sources){return new CompositeObservable(sources)}class ObservableMutableValue{_value;changed=observable();constructor(initialValue){this._value=initialValue}subscribe(observer,handler){this.changed.subscribe(observer,handler)}hasObserver(observer){return this.changed.hasObserver(observer)}unsubscribe(observer){this.changed.unsubscribe(observer)}unsubscribeAll(){this.changed.unsubscribeAll()}async notify(value){return this.changed.notify(value)}get value(){return this._value}set value(newValue){this._value!==newValue&&(this._value=newValue,this.changed.notify(this._value))}}function observableValue(initialValue){return new ObservableMutableValue(initialValue)}class ObservableComputedValue{computeFunc;internalChanged=observable();changed={subscribe:(o,h)=>this.subscribe(o,h),hasObserver:o=>this.hasObserver(o),unsubscribe:o=>this.unsubscribe(o),unsubscribeAll:()=>this.unsubscribeAll(),notify:v=>this.notify(v)};depsChanged;deps;onDepsChangedRef=this.onDepsChanged.bind(this);observerCount=0;hasValue=!1;cachedValue;constructor(computeFunc,...deps){this.computeFunc=computeFunc,this.deps=deps;const sources=deps.map((it=>it.changed));this.depsChanged=compositeObservable(...sources)}subscribe(observer,handler){const observerAlreadySubscribed=this.hasObserver(observer),isFirstObserver=0===this.observerCount;this.internalChanged.subscribe(observer,handler),observerAlreadySubscribed||this.observerCount++,isFirstObserver&&this.depsChanged.subscribe(this,this.onDepsChangedRef)}hasObserver(observer){return this.internalChanged.hasObserver(observer)}unsubscribe(observer){this.internalChanged.hasObserver(observer)&&(this.internalChanged.unsubscribe(observer),this.observerCount--,0===this.observerCount&&this.depsChanged.unsubscribe(this))}unsubscribeAll(){const hadObservers=this.observerCount>0;this.internalChanged.unsubscribeAll(),this.observerCount=0,hadObservers&&this.depsChanged.unsubscribe(this)}async notify(value){throw new Error("ComputedProperty cannot be notified directly")}get value(){return 0===this.observerCount?this.compute():(this.hasValue||(this.cachedValue=this.compute(),this.hasValue=!0),this.cachedValue)}compute(){const values=this.deps.map((d=>d.value));return this.computeFunc(...values)}onDepsChanged(){const newValue=this.compute();this.hasValue&&Object.is(this.cachedValue,newValue)||(this.cachedValue=newValue,this.hasValue=!0,this.internalChanged.notify(this.cachedValue))}}function observableComputed(computeFunc,...deps){return new ObservableComputedValue(computeFunc,...deps)}export{CompositeObservable,DefaultObservable,ObservableComputedValue,ObservableMutableValue,compositeObservable,observable,observableComputed,observableValue};
1
+ class DefaultObservable{observers=new Set;handlers=new Map;subscribe(observer,handler){this.observers.add(observer),this.handlers.set(observer,handler.bind(observer))}hasObserver(observer){return this.observers.has(observer)}unsubscribe(observer){this.observers.delete(observer),this.handlers.delete(observer)}unsubscribeAll(){this.observers.clear(),this.handlers.clear()}async notify(value){let promises=[];for(const handler of this.handlers.values())promises.push(handler(value));await Promise.all(promises)}}function observable(){return new DefaultObservable}class CompositeObservable{sources;observers=new Set;handlers=new Map;onSourceEventRef=this.onSourceEvent.bind(this);constructor(sources){this.sources=sources}hasObserver(observer){return this.observers.has(observer)}async notify(value){throw new Error("CompositeObservable cannot be notified directly")}subscribe(observer,handler){const isFirstObserver=0===this.observers.size;this.observers.add(observer),this.handlers.set(observer,handler.bind(observer)),isFirstObserver&&this.attachToSources()}unsubscribe(observer){const hadObservers=this.observers.size>0;this.observers.delete(observer),this.handlers.delete(observer),hadObservers&&0===this.observers.size&&this.detachFromSources()}unsubscribeAll(){const hadObservers=this.observers.size>0;this.observers.clear(),this.handlers.clear(),hadObservers&&this.detachFromSources()}attachToSources(){for(const source of this.sources)source.subscribe(this,this.onSourceEventRef)}detachFromSources(){for(const source of this.sources)source.unsubscribe(this)}async onSourceEvent(value){let promises=[];for(const handler of this.handlers.values())promises.push(handler(value));await Promise.all(promises)}}function compositeObservable(...sources){return new CompositeObservable(sources)}class DerivedObservable{source;predicate;mapper;observers=new Set;handlers=new Map;onSourceEventRef=this.onSourceEvent.bind(this);constructor(source,predicate=(()=>!0),mapper){this.source=source,this.predicate=predicate,this.mapper=mapper}hasObserver(observer){return this.observers.has(observer)}async notify(_value){throw new Error("DerivedObservable cannot be notified directly")}subscribe(observer,handler){const isFirstObserver=0===this.observers.size;this.observers.add(observer),this.handlers.set(observer,handler.bind(observer)),isFirstObserver&&this.attachToSource()}unsubscribe(observer){const hadObservers=this.observers.size>0;this.observers.delete(observer),this.handlers.delete(observer),hadObservers&&0===this.observers.size&&this.detachFromSource()}unsubscribeAll(){const hadObservers=this.observers.size>0;this.observers.clear(),this.handlers.clear(),hadObservers&&this.detachFromSource()}attachToSource(){this.source.subscribe(this,this.onSourceEventRef)}detachFromSource(){this.source.unsubscribe(this)}async onSourceEvent(value){if(!this.predicate(value))return;const mapped=this.mapper?this.mapper(value):value;let promises=[];for(const handler of this.handlers.values())promises.push(handler(mapped));await Promise.all(promises)}}function derivedObservable(source,predicate,mapper){return new DerivedObservable(source,predicate,mapper)}class ObservableMutableValue{_value;changed=observable();constructor(initialValue){this._value=initialValue}subscribe(observer,handler){this.changed.subscribe(observer,handler)}hasObserver(observer){return this.changed.hasObserver(observer)}unsubscribe(observer){this.changed.unsubscribe(observer)}unsubscribeAll(){this.changed.unsubscribeAll()}async notify(value){return this.changed.notify(value)}get value(){return this._value}set value(newValue){this._value!==newValue&&(this._value=newValue,this.changed.notify(this._value))}}function observableValue(initialValue){return new ObservableMutableValue(initialValue)}class ObservableComputedValue{computeFunc;internalChanged=observable();changed={subscribe:(o,h)=>this.subscribe(o,h),hasObserver:o=>this.hasObserver(o),unsubscribe:o=>this.unsubscribe(o),unsubscribeAll:()=>this.unsubscribeAll(),notify:v=>this.notify(v)};depsChanged;deps;onDepsChangedRef=this.onDepsChanged.bind(this);observerCount=0;hasValue=!1;cachedValue;constructor(computeFunc,...deps){this.computeFunc=computeFunc,this.deps=deps;const sources=deps.map((it=>it.changed));this.depsChanged=compositeObservable(...sources)}subscribe(observer,handler){const observerAlreadySubscribed=this.hasObserver(observer),isFirstObserver=0===this.observerCount;this.internalChanged.subscribe(observer,handler),observerAlreadySubscribed||this.observerCount++,isFirstObserver&&this.depsChanged.subscribe(this,this.onDepsChangedRef)}hasObserver(observer){return this.internalChanged.hasObserver(observer)}unsubscribe(observer){this.internalChanged.hasObserver(observer)&&(this.internalChanged.unsubscribe(observer),this.observerCount--,0===this.observerCount&&this.depsChanged.unsubscribe(this))}unsubscribeAll(){const hadObservers=this.observerCount>0;this.internalChanged.unsubscribeAll(),this.observerCount=0,hadObservers&&this.depsChanged.unsubscribe(this)}async notify(value){throw new Error("ComputedProperty cannot be notified directly")}get value(){return 0===this.observerCount?this.compute():(this.hasValue||(this.cachedValue=this.compute(),this.hasValue=!0),this.cachedValue)}compute(){const values=this.deps.map((d=>d.value));return this.computeFunc(...values)}onDepsChanged(){const newValue=this.compute();this.hasValue&&Object.is(this.cachedValue,newValue)||(this.cachedValue=newValue,this.hasValue=!0,this.internalChanged.notify(this.cachedValue))}}function observableComputed(computeFunc,...deps){return new ObservableComputedValue(computeFunc,...deps)}export{CompositeObservable,DefaultObservable,DerivedObservable,ObservableComputedValue,ObservableMutableValue,compositeObservable,derivedObservable,observable,observableComputed,observableValue};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/DefaultObservable.ts","../../src/CompositeObservable.ts","../../src/ObservableMutableValue.ts","../../src/ObservableComputedValue.ts"],"sourcesContent":["import { Observable, ObserverFunc } from './Observable'\n\nexport class DefaultObservable<T = void> implements Observable<T> {\n private observers: Set<object> = new Set()\n private handlers: Map<object, ObserverFunc<T>> = new Map()\n\n subscribe(observer: object, handler: ObserverFunc<T>) {\n this.observers.add(observer)\n this.handlers.set(observer, handler.bind(observer))\n }\n\n hasObserver(observer: object) {\n return this.observers.has(observer)\n }\n\n unsubscribe(observer: object) {\n this.observers.delete(observer)\n this.handlers.delete(observer)\n }\n\n unsubscribeAll() {\n this.observers.clear()\n this.handlers.clear()\n }\n\n async notify(value?: T) {\n let promises = []\n for (const handler of this.handlers.values()) {\n promises.push(handler(value))\n }\n await Promise.all(promises)\n }\n}\n\nexport function observable<T = void>(): Observable<T> {\n return new DefaultObservable<T>()\n}\n","import { Observable, ObserverFunc } from './Observable'\n\ntype EventOf<O> = O extends Observable<infer T> ? T : never\n\nexport class CompositeObservable<Sources extends readonly Observable<any>[]> implements Observable<EventOf<Sources[number]>> {\n private observers = new Set<object>()\n private handlers: Map<object, ObserverFunc<EventOf<Sources[number]>>> = new Map()\n private onSourceEventRef = this.onSourceEvent.bind(this)\n\n constructor(private readonly sources: Sources) {\n }\n\n hasObserver(observer: object): boolean {\n return this.observers.has(observer)\n }\n\n async notify(value?: EventOf<Sources[number]>) {\n throw new Error('CompositeObservable cannot be notified directly')\n }\n\n subscribe(observer: object, handler: ObserverFunc<EventOf<Sources[number]>>): void {\n const isFirstObserver = this.observers.size === 0\n this.observers.add(observer)\n this.handlers.set(observer, handler.bind(observer))\n\n if (isFirstObserver) this.attachToSources()\n }\n\n unsubscribe(observer: object): void {\n const hadObservers = this.observers.size > 0\n this.observers.delete(observer)\n this.handlers.delete(observer)\n\n if (hadObservers && this.observers.size === 0) this.detachFromSources()\n }\n\n unsubscribeAll(): void {\n const hadObservers = this.observers.size > 0\n this.observers.clear()\n this.handlers.clear()\n if (hadObservers ) this.detachFromSources()\n }\n\n private attachToSources() {\n for (const source of this.sources) {\n source.subscribe(this, this.onSourceEventRef)\n }\n }\n\n private detachFromSources() {\n for (const source of this.sources) {\n source.unsubscribe(this)\n }\n }\n\n private async onSourceEvent(value?: EventOf<Sources[number]>) {\n let promises = []\n for (const handler of this.handlers.values()) {\n promises.push(handler(value))\n }\n await Promise.all(promises)\n }\n}\n\nexport function compositeObservable<Sources extends readonly Observable<any>[]>(...sources: Sources) {\n return new CompositeObservable(sources)\n}\n","import { observable } from './DefaultObservable'\nimport { ObserverFunc } from './Observable'\nimport { ObservableValue } from './ObservableValue'\n\nexport class ObservableMutableValue<T> implements ObservableValue<T> {\n private _value: T\n readonly changed = observable<T>()\n\n constructor(initialValue: T) {\n this._value = initialValue\n }\n\n subscribe(observer: object, handler: ObserverFunc<T>) {\n this.changed.subscribe(observer, handler)\n }\n hasObserver(observer: object): boolean {\n return this.changed.hasObserver(observer)\n }\n unsubscribe(observer: object) {\n this.changed.unsubscribe(observer)\n }\n unsubscribeAll() {\n this.changed.unsubscribeAll()\n }\n\n async notify(value?: T): Promise<void> {\n return this.changed.notify(value)\n }\n\n get value(): T {\n return this._value\n }\n\n set value(newValue: T) {\n if (this._value === newValue) return\n this._value = newValue\n this.changed.notify(this._value)\n }\n}\n\nexport function observableValue<T>(initialValue: T): ObservableMutableValue<T> {\n return new ObservableMutableValue<T>(initialValue)\n}\n","import { ObservableValue } from './ObservableValue'\nimport { Observable, ObserverFunc } from './Observable'\nimport { compositeObservable } from './CompositeObservable'\nimport { observable } from './DefaultObservable'\n\ntype ValueOf<P> = P extends ObservableValue<infer T> ? T : never\n\nexport class ObservableComputedValue<Deps extends readonly ObservableValue<any>[], T> implements ObservableValue<T> {\n private readonly internalChanged = observable<T>()\n readonly changed: Observable<T> = {\n subscribe: (o, h) => this.subscribe(o, h),\n hasObserver: (o) => this.hasObserver(o),\n unsubscribe: (o) => this.unsubscribe(o),\n unsubscribeAll: () => this.unsubscribeAll(),\n notify: (v) => this.notify(v),\n }\n private readonly depsChanged: Observable<any>\n private readonly deps: Deps\n private readonly onDepsChangedRef = this.onDepsChanged.bind(this)\n private observerCount = 0\n private hasValue = false\n private cachedValue!: T\n\n constructor(private readonly computeFunc: (...values: { [K in keyof Deps]: ValueOf<Deps[K]> }) => T, ...deps: Deps) {\n this.deps = deps\n const sources = deps.map(it => it.changed)\n this.depsChanged = compositeObservable(...sources)\n }\n\n subscribe(observer: object, handler: ObserverFunc<any>) {\n const observerAlreadySubscribed = this.hasObserver(observer)\n const isFirstObserver = this.observerCount === 0\n this.internalChanged.subscribe(observer, handler)\n if (!observerAlreadySubscribed) {\n this.observerCount++\n }\n if (isFirstObserver) this.depsChanged.subscribe(this, this.onDepsChangedRef)\n }\n\n hasObserver(observer: object): boolean {\n return this.internalChanged.hasObserver(observer)\n }\n\n unsubscribe(observer: object) {\n if (!this.internalChanged.hasObserver(observer)) return\n\n this.internalChanged.unsubscribe(observer)\n this.observerCount--\n\n if (this.observerCount === 0) this.depsChanged.unsubscribe(this)\n }\n\n unsubscribeAll() {\n const hadObservers = this.observerCount > 0\n this.internalChanged.unsubscribeAll()\n this.observerCount = 0\n if (hadObservers) this.depsChanged.unsubscribe(this)\n }\n\n async notify(value?: any): Promise<void> {\n throw new Error('ComputedProperty cannot be notified directly')\n }\n\n get value(): T {\n // When there are no observers we must recompute on each call because we aren't watching dep changes\n if (this.observerCount === 0) return this.compute()\n\n if (!this.hasValue) {\n this.cachedValue = this.compute()\n this.hasValue = true\n }\n return this.cachedValue\n }\n\n private compute(): T {\n const values = this.deps.map(d => d.value) as { [K in keyof Deps]: ValueOf<Deps[K]> }\n return this.computeFunc(...values)\n }\n\n private onDepsChanged() {\n const newValue = this.compute()\n\n if (!this.hasValue || !Object.is(this.cachedValue, newValue)) {\n this.cachedValue = newValue\n this.hasValue = true\n this.internalChanged.notify(this.cachedValue)\n }\n }\n}\n\nexport function observableComputed<\n Deps extends readonly ObservableValue<any>[],\n T,\n>(computeFunc: (...values: { [K in keyof Deps]: ValueOf<Deps[K]> }) => T, ...deps: Deps) {\n return new ObservableComputedValue(computeFunc, ...deps)\n}\n"],"names":["DefaultObservable","observers","Set","handlers","Map","subscribe","observer","handler","this","add","set","bind","hasObserver","has","unsubscribe","delete","unsubscribeAll","clear","notify","value","promises","values","push","Promise","all","observable","CompositeObservable","sources","onSourceEventRef","onSourceEvent","constructor","Error","isFirstObserver","size","attachToSources","hadObservers","detachFromSources","source","compositeObservable","ObservableMutableValue","_value","changed","initialValue","newValue","observableValue","ObservableComputedValue","computeFunc","internalChanged","o","h","v","depsChanged","deps","onDepsChangedRef","onDepsChanged","observerCount","hasValue","cachedValue","map","it","observerAlreadySubscribed","compute","d","Object","is","observableComputed"],"mappings":"MAEaA,kBACDC,UAAyB,IAAIC,IAC7BC,SAAyC,IAAIC,IAErD,SAAAC,CAAUC,SAAkBC,SACxBC,KAAKP,UAAUQ,IAAIH,UACnBE,KAAKL,SAASO,IAAIJ,SAAUC,QAAQI,KAAKL,UAC5C,CAED,WAAAM,CAAYN,UACR,OAAOE,KAAKP,UAAUY,IAAIP,SAC7B,CAED,WAAAQ,CAAYR,UACRE,KAAKP,UAAUc,OAAOT,UACtBE,KAAKL,SAASY,OAAOT,SACxB,CAED,cAAAU,GACIR,KAAKP,UAAUgB,QACfT,KAAKL,SAASc,OACjB,CAED,YAAMC,CAAOC,OACT,IAAIC,SAAW,GACf,IAAK,MAAMb,WAAWC,KAAKL,SAASkB,SAChCD,SAASE,KAAKf,QAAQY,cAEpBI,QAAQC,IAAIJ,SACrB,WAGWK,aACZ,OAAO,IAAIzB,iBACf,OChCa0B,oBAKoBC,QAJrB1B,UAAY,IAAIC,IAChBC,SAAgE,IAAIC,IACpEwB,iBAAmBpB,KAAKqB,cAAclB,KAAKH,MAEnD,WAAAsB,CAA6BH,SAAAnB,KAAOmB,QAAPA,OAC5B,CAED,WAAAf,CAAYN,UACR,OAAOE,KAAKP,UAAUY,IAAIP,SAC7B,CAED,YAAMY,CAAOC,OACT,MAAM,IAAIY,MAAM,kDACnB,CAED,SAAA1B,CAAUC,SAAkBC,SACxB,MAA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GACI,MAAMmB,aAAe3B,KAAK+C,cAAgB,EAC1C/C,KAAKuC,gBAAgB/B,iBACrBR,KAAK+C,cAAgB,EACjBpB,cAAc3B,KAAK2C,YAAYrC,YAAYN,KAClD,CAED,YAAMU,CAAOC,OACT,MAAM,IAAIY,MAAM,+CACnB,CAED,SAAIZ,GAEA,OAA2B,IAAvBX,KAAK+C,cAA4B/C,KAAKqD,WAErCrD,KAAKgD,WACNhD,KAAKiD,YAAcjD,KAAKqD,UACxBrD,KAAKgD,UAAW,GAEbhD,KAAKiD,YACf,CAEO,OAAAI,GACJ,MAAMxC,OAASb,KAAK4C,KAAKM,KAAII,GAAKA,EAAE3C,QACpC,OAAOX,KAAKsC,eAAezB,OAC9B,CAEO,aAAAiC,GACJ,MAAMX,SAAWnC,KAAKqD,UAEjBrD,KAAKgD,UAAaO,OAAOC,GAAGxD,KAAKiD,YAAad,YAC/CnC,KAAKiD,YAAcd,SACnBnC,KAAKgD,UAAW,EAChBhD,KAAKuC,gBAAgB7B,OAAOV,KAAKiD,aAExC,WAGWQ,mBAGdnB,eAA2EM,MACzE,OAAO,IAAIP,wBAAwBC,eAAgBM,KACvD"}
1
+ {"version":3,"file":"index.js","sources":["../../src/DefaultObservable.ts","../../src/CompositeObservable.ts","../../src/DerivedObservable.ts","../../src/ObservableMutableValue.ts","../../src/ObservableComputedValue.ts"],"sourcesContent":["import { Observable, ObserverFunc } from './Observable'\n\nexport class DefaultObservable<T = void> implements Observable<T> {\n private observers: Set<object> = new Set()\n private handlers: Map<object, ObserverFunc<T>> = new Map()\n\n subscribe(observer: object, handler: ObserverFunc<T>) {\n this.observers.add(observer)\n this.handlers.set(observer, handler.bind(observer))\n }\n\n hasObserver(observer: object) {\n return this.observers.has(observer)\n }\n\n unsubscribe(observer: object) {\n this.observers.delete(observer)\n this.handlers.delete(observer)\n }\n\n unsubscribeAll() {\n this.observers.clear()\n this.handlers.clear()\n }\n\n async notify(value?: T) {\n let promises = []\n for (const handler of this.handlers.values()) {\n promises.push(handler(value))\n }\n await Promise.all(promises)\n }\n}\n\nexport function observable<T = void>(): Observable<T> {\n return new DefaultObservable<T>()\n}\n","import { Observable, ObserverFunc } from './Observable'\n\ntype EventOf<O> = O extends Observable<infer T> ? T : never\n\nexport class CompositeObservable<Sources extends readonly Observable<any>[]> implements Observable<EventOf<Sources[number]>> {\n private observers = new Set<object>()\n private handlers: Map<object, ObserverFunc<EventOf<Sources[number]>>> = new Map()\n private onSourceEventRef = this.onSourceEvent.bind(this)\n\n constructor(private readonly sources: Sources) {\n }\n\n hasObserver(observer: object): boolean {\n return this.observers.has(observer)\n }\n\n async notify(value?: EventOf<Sources[number]>) {\n throw new Error('CompositeObservable cannot be notified directly')\n }\n\n subscribe(observer: object, handler: ObserverFunc<EventOf<Sources[number]>>): void {\n const isFirstObserver = this.observers.size === 0\n this.observers.add(observer)\n this.handlers.set(observer, handler.bind(observer))\n\n if (isFirstObserver) this.attachToSources()\n }\n\n unsubscribe(observer: object): void {\n const hadObservers = this.observers.size > 0\n this.observers.delete(observer)\n this.handlers.delete(observer)\n\n if (hadObservers && this.observers.size === 0) this.detachFromSources()\n }\n\n unsubscribeAll(): void {\n const hadObservers = this.observers.size > 0\n this.observers.clear()\n this.handlers.clear()\n if (hadObservers ) this.detachFromSources()\n }\n\n private attachToSources() {\n for (const source of this.sources) {\n source.subscribe(this, this.onSourceEventRef)\n }\n }\n\n private detachFromSources() {\n for (const source of this.sources) {\n source.unsubscribe(this)\n }\n }\n\n private async onSourceEvent(value?: EventOf<Sources[number]>) {\n let promises = []\n for (const handler of this.handlers.values()) {\n promises.push(handler(value))\n }\n await Promise.all(promises)\n }\n}\n\nexport function compositeObservable<Sources extends readonly Observable<any>[]>(...sources: Sources) {\n return new CompositeObservable(sources)\n}\n","import { Observable, ObserverFunc } from './Observable'\n\ntype Mapper<S, T> = (value?: S) => T\ntype Predicate<S> = (value?: S) => boolean\n\nexport class DerivedObservable<S, T = S> implements Observable<T> {\n private observers = new Set<object>()\n private handlers: Map<object, ObserverFunc<T>> = new Map()\n private onSourceEventRef = this.onSourceEvent.bind(this)\n\n constructor(\n private readonly source: Observable<S>,\n private readonly predicate: Predicate<S> = () => true,\n private readonly mapper?: Mapper<S, T>,\n ) {}\n\n hasObserver(observer: object): boolean {\n return this.observers.has(observer)\n }\n\n async notify(_value?: T) {\n throw new Error('DerivedObservable cannot be notified directly')\n }\n\n subscribe(observer: object, handler: ObserverFunc<T>): void {\n const isFirstObserver = this.observers.size === 0\n\n this.observers.add(observer)\n this.handlers.set(observer, handler.bind(observer))\n\n if (isFirstObserver) this.attachToSource()\n }\n\n unsubscribe(observer: object): void {\n const hadObservers = this.observers.size > 0\n\n this.observers.delete(observer)\n this.handlers.delete(observer)\n\n if (hadObservers && this.observers.size === 0) this.detachFromSource()\n }\n\n unsubscribeAll(): void {\n const hadObservers = this.observers.size > 0\n this.observers.clear()\n this.handlers.clear()\n if (hadObservers) this.detachFromSource()\n }\n\n private attachToSource() {\n this.source.subscribe(this, this.onSourceEventRef)\n }\n\n private detachFromSource() {\n this.source.unsubscribe(this)\n }\n\n private async onSourceEvent(value?: S) {\n if (!this.predicate(value)) return\n\n const mapped = this.mapper ? this.mapper(value) : (value as unknown as T)\n\n let promises = []\n for (const handler of this.handlers.values()) {\n promises.push(handler(mapped))\n }\n await Promise.all(promises)\n }\n}\n\nexport function derivedObservable<S, T = S>(\n source: Observable<S>,\n predicate: Predicate<S>,\n mapper?: Mapper<S, T>,\n) {\n return new DerivedObservable<S, T>(source, predicate, mapper)\n}\n","import { observable } from './DefaultObservable'\nimport { ObserverFunc } from './Observable'\nimport { ObservableValue } from './ObservableValue'\n\nexport class ObservableMutableValue<T> implements ObservableValue<T> {\n private _value: T\n readonly changed = observable<T>()\n\n constructor(initialValue: T) {\n this._value = initialValue\n }\n\n subscribe(observer: object, handler: ObserverFunc<T>) {\n this.changed.subscribe(observer, handler)\n }\n hasObserver(observer: object): boolean {\n return this.changed.hasObserver(observer)\n }\n unsubscribe(observer: object) {\n this.changed.unsubscribe(observer)\n }\n unsubscribeAll() {\n this.changed.unsubscribeAll()\n }\n\n async notify(value?: T): Promise<void> {\n return this.changed.notify(value)\n }\n\n get value(): T {\n return this._value\n }\n\n set value(newValue: T) {\n if (this._value === newValue) return\n this._value = newValue\n this.changed.notify(this._value)\n }\n}\n\nexport function observableValue<T>(initialValue: T): ObservableMutableValue<T> {\n return new ObservableMutableValue<T>(initialValue)\n}\n","import { ObservableValue } from './ObservableValue'\nimport { Observable, ObserverFunc } from './Observable'\nimport { compositeObservable } from './CompositeObservable'\nimport { observable } from './DefaultObservable'\n\ntype ValueOf<P> = P extends ObservableValue<infer T> ? T : never\n\nexport class ObservableComputedValue<Deps extends readonly ObservableValue<any>[], T> implements ObservableValue<T> {\n private readonly internalChanged = observable<T>()\n readonly changed: Observable<T> = {\n subscribe: (o, h) => this.subscribe(o, h),\n hasObserver: (o) => this.hasObserver(o),\n unsubscribe: (o) => this.unsubscribe(o),\n unsubscribeAll: () => this.unsubscribeAll(),\n notify: (v) => this.notify(v),\n }\n private readonly depsChanged: Observable<any>\n private readonly deps: Deps\n private readonly onDepsChangedRef = this.onDepsChanged.bind(this)\n private observerCount = 0\n private hasValue = false\n private cachedValue!: T\n\n constructor(private readonly computeFunc: (...values: { [K in keyof Deps]: ValueOf<Deps[K]> }) => T, ...deps: Deps) {\n this.deps = deps\n const sources = deps.map(it => it.changed)\n this.depsChanged = compositeObservable(...sources)\n }\n\n subscribe(observer: object, handler: ObserverFunc<any>) {\n const observerAlreadySubscribed = this.hasObserver(observer)\n const isFirstObserver = this.observerCount === 0\n this.internalChanged.subscribe(observer, handler)\n if (!observerAlreadySubscribed) {\n this.observerCount++\n }\n if (isFirstObserver) this.depsChanged.subscribe(this, this.onDepsChangedRef)\n }\n\n hasObserver(observer: object): boolean {\n return this.internalChanged.hasObserver(observer)\n }\n\n unsubscribe(observer: object) {\n if (!this.internalChanged.hasObserver(observer)) return\n\n this.internalChanged.unsubscribe(observer)\n this.observerCount--\n\n if (this.observerCount === 0) this.depsChanged.unsubscribe(this)\n }\n\n unsubscribeAll() {\n const hadObservers = this.observerCount > 0\n this.internalChanged.unsubscribeAll()\n this.observerCount = 0\n if (hadObservers) this.depsChanged.unsubscribe(this)\n }\n\n async notify(value?: any): Promise<void> {\n throw new Error('ComputedProperty cannot be notified directly')\n }\n\n get value(): T {\n // When there are no observers we must recompute on each call because we aren't watching dep changes\n if (this.observerCount === 0) return this.compute()\n\n if (!this.hasValue) {\n this.cachedValue = this.compute()\n this.hasValue = true\n }\n return this.cachedValue\n }\n\n private compute(): T {\n const values = this.deps.map(d => d.value) as { [K in keyof Deps]: ValueOf<Deps[K]> }\n return this.computeFunc(...values)\n }\n\n private onDepsChanged() {\n const newValue = this.compute()\n\n if (!this.hasValue || !Object.is(this.cachedValue, newValue)) {\n this.cachedValue = newValue\n this.hasValue = true\n this.internalChanged.notify(this.cachedValue)\n }\n }\n}\n\nexport function observableComputed<\n Deps extends readonly ObservableValue<any>[],\n T,\n>(computeFunc: (...values: { [K in keyof Deps]: ValueOf<Deps[K]> }) => T, ...deps: Deps) {\n return new ObservableComputedValue(computeFunc, ...deps)\n}\n"],"names":["DefaultObservable","observers","Set","handlers","Map","subscribe","observer","handler","this","add","set","bind","hasObserver","has","unsubscribe","delete","unsubscribeAll","clear","notify","value","promises","values","push","Promise","all","observable","CompositeObservable","sources","onSourceEventRef","onSourceEvent","constructor","Error","isFirstObserver","size","attachToSources","hadObservers","detachFromSources","source","compositeObservable","DerivedObservable","predicate","mapper","_value","attachToSource","detachFromSource","mapped","derivedObservable","ObservableMutableValue","changed","initialValue","newValue","observableValue","ObservableComputedValue","computeFunc","internalChanged","o","h","v","depsChanged","deps","onDepsChangedRef","onDepsChanged","observerCount","hasValue","cachedValue","map","it","observerAlreadySubscribed","compute","d","Object","is","observableComputed"],"mappings":"MAEaA,kBACDC,UAAyB,IAAIC,IAC7BC,SAAyC,IAAIC,IAErD,SAAAC,CAAUC,SAAkBC,SACxBC,K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,KAAKM,KAAII,GAAKA,EAAElD,QACpC,OAAOX,KAAK6C,eAAehC,OAC9B,CAEO,aAAAwC,GACJ,MAAMX,SAAW1C,KAAK4D,UAEjB5D,KAAKuD,UAAaO,OAAOC,GAAG/D,KAAKwD,YAAad,YAC/C1C,KAAKwD,YAAcd,SACnB1C,KAAKuD,UAAW,EAChBvD,KAAK8C,gBAAgBpC,OAAOV,KAAKwD,aAExC,WAGWQ,mBAGdnB,eAA2EM,MACzE,OAAO,IAAIP,wBAAwBC,eAAgBM,KACvD"}
@@ -41,6 +41,27 @@ declare class CompositeObservable<Sources extends readonly Observable<any>[]> im
41
41
  }
42
42
  declare function compositeObservable<Sources extends readonly Observable<any>[]>(...sources: Sources): CompositeObservable<Sources>;
43
43
 
44
+ type Mapper<S, T> = (value?: S) => T;
45
+ type Predicate<S> = (value?: S) => boolean;
46
+ declare class DerivedObservable<S, T = S> implements Observable<T> {
47
+ private readonly source;
48
+ private readonly predicate;
49
+ private readonly mapper?;
50
+ private observers;
51
+ private handlers;
52
+ private onSourceEventRef;
53
+ constructor(source: Observable<S>, predicate?: Predicate<S>, mapper?: Mapper<S, T>);
54
+ hasObserver(observer: object): boolean;
55
+ notify(_value?: T): Promise<void>;
56
+ subscribe(observer: object, handler: ObserverFunc<T>): void;
57
+ unsubscribe(observer: object): void;
58
+ unsubscribeAll(): void;
59
+ private attachToSource;
60
+ private detachFromSource;
61
+ private onSourceEvent;
62
+ }
63
+ declare function derivedObservable<S, T = S>(source: Observable<S>, predicate: Predicate<S>, mapper?: Mapper<S, T>): DerivedObservable<S, T>;
64
+
44
65
  declare class ObservableMutableValue<T> implements ObservableValue<T> {
45
66
  private _value;
46
67
  readonly changed: Observable<T>;
@@ -82,4 +103,4 @@ declare function observableComputed<Deps extends readonly ObservableValue<any>[]
82
103
  [K in keyof Deps]: ValueOf<Deps[K]>;
83
104
  }) => T, ...deps: Deps): ObservableComputedValue<[...Deps], T>;
84
105
 
85
- export { CompositeObservable, DefaultObservable, Observable, ObservableComputedValue, ObservableMutableValue, ObservableValue, ObserverFunc, compositeObservable, observable, observableComputed, observableValue };
106
+ export { CompositeObservable, DefaultObservable, DerivedObservable, Observable, ObservableComputedValue, ObservableMutableValue, ObservableValue, ObserverFunc, compositeObservable, derivedObservable, observable, observableComputed, observableValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nbottarini/observable",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Tiny Observable pattern implementation for creating observable properties",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",