@nbottarini/observable 0.2.2 → 0.4.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/README.md CHANGED
@@ -47,3 +47,12 @@ export class View2 {
47
47
  }
48
48
  }
49
49
  ```
50
+
51
+ **Observable properties:**
52
+
53
+ ```typescript
54
+ const nameProperty = new ObservableProperty('John')
55
+ nameProperty.changed.subscribe(this, this.onNameChanged)
56
+
57
+ nameProperty.value = 'new name'
58
+ ```
package/dist/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";exports.Observable=class{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()}notify(value){for(const handler of this.handlers.values())handler(value)}};
1
+ "use strict";exports.Observable=class{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)}};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/Observable.ts"],"sourcesContent":["export type ObserverFunc<T> = (subject: T) => void\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 notify(value?: T) {\n for (const handler of this.handlers.values()) {\n // @ts-ignore\n handler(value)\n }\n }\n}\n"],"names":["observers","Set","handlers","Map","subscribe","observer","handler","this","add","set","bind","unsubscribe","delete","unsubscribeAll","clear","notify","value","values"],"mappings":"sCAGYA,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,MAAAC,CAAOC,OACH,IAAK,MAAMV,WAAWC,KAAKL,SAASe,SAEhCX,QAAQU,MAEf"}
1
+ {"version":3,"file":"index.js","sources":["../../src/Observable.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"],"names":["observers","Set","handlers","Map","subscribe","observer","handler","this","add","set","bind","unsubscribe","delete","unsubscribeAll","clear","notify","value","promises","values","push","Promise","all"],"mappings":"sCAGYA,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"}
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()}notify(value){for(const handler of this.handlers.values())handler(value)}}export{Observable};
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)}}export{Observable};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/Observable.ts"],"sourcesContent":["export type ObserverFunc<T> = (subject: T) => void\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 notify(value?: T) {\n for (const handler of this.handlers.values()) {\n // @ts-ignore\n handler(value)\n }\n }\n}\n"],"names":["Observable","observers","Set","handlers","Map","subscribe","observer","handler","this","add","set","bind","unsubscribe","delete","unsubscribeAll","clear","notify","value","values"],"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,MAAAC,CAAOC,OACH,IAAK,MAAMV,WAAWC,KAAKL,SAASe,SAEhCX,QAAQU,MAEf"}
1
+ {"version":3,"file":"index.js","sources":["../../src/Observable.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"],"names":["Observable","observers","Set","handlers","Map","subscribe","observer","handler","this","add","set","bind","unsubscribe","delete","unsubscribeAll","clear","notify","value","promises","values","push","Promise","all"],"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"}
@@ -1,11 +1,11 @@
1
- type ObserverFunc<T> = (subject: T) => void;
1
+ type ObserverFunc<T> = (subject: T) => any;
2
2
  declare class Observable<T = void> {
3
3
  private observers;
4
4
  private handlers;
5
5
  subscribe(observer: object, handler: ObserverFunc<T>): void;
6
6
  unsubscribe(observer: object): void;
7
7
  unsubscribeAll(): void;
8
- notify(value?: T): void;
8
+ notify(value?: T): Promise<void>;
9
9
  }
10
10
 
11
11
  export { Observable };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nbottarini/observable",
3
- "version": "0.2.2",
3
+ "version": "0.4.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",