@nbottarini/observable 0.4.1 → 0.5.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 Observable{observers=new Set;handlers=new Map;subscribe(observer,handler){this.observers.add(observer),this.handlers.set(observer,handler.bind(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)}}exports.Observable=Observable,exports.ObservableProperty=class{_value;changed=new Observable;constructor(initialValue){this._value=initialValue}get value(){return this._value}set value(newValue){this._value!==newValue&&(this._value=newValue,this.changed.notify(this._value))}};
1
+ "use strict";class Observable{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)}}exports.Observable=Observable,exports.ObservableProperty=class{_value;changed=new Observable;constructor(initialValue){this._value=initialValue}get value(){return this._value}set value(newValue){this._value!==newValue&&(this._value=newValue,this.changed.notify(this._value))}};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/Observable.ts","../../src/ObservableProperty.ts"],"sourcesContent":["export type ObserverFunc<T> = (subject: T) => any\n\nexport class Observable<T = void> {\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 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","import { Observable } from './Observable'\n\nexport class ObservableProperty<T = any> {\n private _value: T\n readonly changed: Observable<T> = new Observable()\n\n constructor(initialValue: T) {\n this._value = initialValue\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"],"names":["Observable","observers","Set","handlers","Map","subscribe","observer","handler","this","add","set","bind","unsubscribe","delete","unsubscribeAll","clear","notify","value","promises","values","push","Promise","all","_value","changed","constructor","initialValue","newValue"],"mappings":"mBAEaA,WACDC,UAAyB,IAAIC,IAC7BC,SAAyC,IAAIC,IAErD,SAAAC,CAAUC,SAAkBC,SACxBC,KAAKP,UAAUQ,IAAIH,UACnBE,KAAKL,SAASO,IAAIJ,SAAUC,QAAQI,KAAKL,UAC5C,CAED,WAAAM,CAAYN,UACRE,KAAKP,UAAUY,OAAOP,UACtBE,KAAKL,SAASU,OAAOP,SACxB,CAED,cAAAQ,GACIN,KAAKP,UAAUc,QACfP,KAAKL,SAASY,OACjB,CAED,YAAMC,CAAOC,OACT,IAAIC,SAAW,GACf,IAAK,MAAMX,WAAWC,KAAKL,SAASgB,SAChCD,SAASE,KAAKb,QAAQU,cAEpBI,QAAQC,IAAIJ,SACrB,iECxBOK,OACCC,QAAyB,IAAIxB,WAEtC,WAAAyB,CAAYC,cACRlB,KAAKe,OAASG,YACjB,CAED,SAAIT,GACA,OAAOT,KAAKe,MACf,CAED,SAAIN,CAAMU,UACFnB,KAAKe,SAAWI,WACpBnB,KAAKe,OAASI,SACdnB,KAAKgB,QAAQR,OAAOR,KAAKe,QAC5B"}
1
+ {"version":3,"file":"index.js","sources":["../../src/Observable.ts","../../src/ObservableProperty.ts"],"sourcesContent":["export type ObserverFunc<T> = (subject: T) => any\n\nexport class Observable<T = void> {\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","import { Observable } from './Observable'\n\nexport class ObservableProperty<T = any> {\n private _value: T\n readonly changed: Observable<T> = new Observable()\n\n constructor(initialValue: T) {\n this._value = initialValue\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"],"names":["Observable","observers","Set","handlers","Map","subscribe","observer","handler","this","add","set","bind","hasObserver","has","unsubscribe","delete","unsubscribeAll","clear","notify","value","promises","values","push","Promise","all","_value","changed","constructor","initialValue","newValue"],"mappings":"mBAEaA,WACDC,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,iEC5BOK,OACCC,QAAyB,IAAI1B,WAEtC,WAAA2B,CAAYC,cACRpB,KAAKiB,OAASG,YACjB,CAED,SAAIT,GACA,OAAOX,KAAKiB,MACf,CAED,SAAIN,CAAMU,UACFrB,KAAKiB,SAAWI,WACpBrB,KAAKiB,OAASI,SACdrB,KAAKkB,QAAQR,OAAOV,KAAKiB,QAC5B"}
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- class Observable{observers=new Set;handlers=new Map;subscribe(observer,handler){this.observers.add(observer),this.handlers.set(observer,handler.bind(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)}}class ObservableProperty{_value;changed=new Observable;constructor(initialValue){this._value=initialValue}get value(){return this._value}set value(newValue){this._value!==newValue&&(this._value=newValue,this.changed.notify(this._value))}}export{Observable,ObservableProperty};
1
+ class Observable{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)}}class ObservableProperty{_value;changed=new Observable;constructor(initialValue){this._value=initialValue}get value(){return this._value}set value(newValue){this._value!==newValue&&(this._value=newValue,this.changed.notify(this._value))}}export{Observable,ObservableProperty};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/Observable.ts","../../src/ObservableProperty.ts"],"sourcesContent":["export type ObserverFunc<T> = (subject: T) => any\n\nexport class Observable<T = void> {\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 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","import { Observable } from './Observable'\n\nexport class ObservableProperty<T = any> {\n private _value: T\n readonly changed: Observable<T> = new Observable()\n\n constructor(initialValue: T) {\n this._value = initialValue\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"],"names":["Observable","observers","Set","handlers","Map","subscribe","observer","handler","this","add","set","bind","unsubscribe","delete","unsubscribeAll","clear","notify","value","promises","values","push","Promise","all","ObservableProperty","_value","changed","constructor","initialValue","newValue"],"mappings":"MAEaA,WACDC,UAAyB,IAAIC,IAC7BC,SAAyC,IAAIC,IAErD,SAAAC,CAAUC,SAAkBC,SACxBC,KAAKP,UAAUQ,IAAIH,UACnBE,KAAKL,SAASO,IAAIJ,SAAUC,QAAQI,KAAKL,UAC5C,CAED,WAAAM,CAAYN,UACRE,KAAKP,UAAUY,OAAOP,UACtBE,KAAKL,SAASU,OAAOP,SACxB,CAED,cAAAQ,GACIN,KAAKP,UAAUc,QACfP,KAAKL,SAASY,OACjB,CAED,YAAMC,CAAOC,OACT,IAAIC,SAAW,GACf,IAAK,MAAMX,WAAWC,KAAKL,SAASgB,SAChCD,SAASE,KAAKb,QAAQU,cAEpBI,QAAQC,IAAIJ,SACrB,QCzBQK,mBACDC,OACCC,QAAyB,IAAIzB,WAEtC,WAAA0B,CAAYC,cACRnB,KAAKgB,OAASG,YACjB,CAED,SAAIV,GACA,OAAOT,KAAKgB,MACf,CAED,SAAIP,CAAMW,UACFpB,KAAKgB,SAAWI,WACpBpB,KAAKgB,OAASI,SACdpB,KAAKiB,QAAQT,OAAOR,KAAKgB,QAC5B"}
1
+ {"version":3,"file":"index.js","sources":["../../src/Observable.ts","../../src/ObservableProperty.ts"],"sourcesContent":["export type ObserverFunc<T> = (subject: T) => any\n\nexport class Observable<T = void> {\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","import { Observable } from './Observable'\n\nexport class ObservableProperty<T = any> {\n private _value: T\n readonly changed: Observable<T> = new Observable()\n\n constructor(initialValue: T) {\n this._value = initialValue\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"],"names":["Observable","observers","Set","handlers","Map","subscribe","observer","handler","this","add","set","bind","hasObserver","has","unsubscribe","delete","unsubscribeAll","clear","notify","value","promises","values","push","Promise","all","ObservableProperty","_value","changed","constructor","initialValue","newValue"],"mappings":"MAEaA,WACDC,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,QC7BQK,mBACDC,OACCC,QAAyB,IAAI3B,WAEtC,WAAA4B,CAAYC,cACRrB,KAAKkB,OAASG,YACjB,CAED,SAAIV,GACA,OAAOX,KAAKkB,MACf,CAED,SAAIP,CAAMW,UACFtB,KAAKkB,SAAWI,WACpBtB,KAAKkB,OAASI,SACdtB,KAAKmB,QAAQT,OAAOV,KAAKkB,QAC5B"}
@@ -3,6 +3,7 @@ declare class Observable<T = void> {
3
3
  private observers;
4
4
  private handlers;
5
5
  subscribe(observer: object, handler: ObserverFunc<T>): void;
6
+ hasObserver(observer: object): boolean;
6
7
  unsubscribe(observer: object): void;
7
8
  unsubscribeAll(): void;
8
9
  notify(value?: T): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nbottarini/observable",
3
- "version": "0.4.1",
3
+ "version": "0.5.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",