@nbottarini/observable 0.2.0 → 0.2.2

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
@@ -1,4 +1,49 @@
1
+ [![npm](https://img.shields.io/npm/v/@nbottarini/observable.svg)](https://www.npmjs.com/package/@nbottarini/observable)
1
2
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3
+ [![CI Status](https://github.com/nbottarini/observable-js/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/nbottarini/observable-js/actions)
2
4
 
3
5
  # Observable-Js
4
6
  Tiny Observable pattern implementation for creating observable properties
7
+ ## Installation
8
+
9
+ Npm:
10
+ ```
11
+ $ npm install --save @nbottarini/observable
12
+ ```
13
+
14
+ Yarn:
15
+ ```
16
+ $ yarn add @nbottarini/observable
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ **View1.ts:**
22
+ ```typescript
23
+ export class View1 {
24
+ public readonly buttonClicked = new Observable<ClickEvent>()
25
+ public readonly textChanged = new Observable<TextChangedEvent>()
26
+
27
+ // Do something internally to handle UI events
28
+
29
+ private handleButtonClick(e: ClickEvent) {
30
+ this.buttonClicked.notify(e)
31
+ }
32
+ }
33
+ ```
34
+
35
+ **View2.ts:**
36
+ ```typescript
37
+ export class View2 {
38
+ private sampleView: View1
39
+
40
+ constructor() {
41
+ this.sampleView = new View1()
42
+ this.sampleView.buttonClicked.subscribe(this, this.onSampleViewButtonClicked)
43
+ }
44
+
45
+ onSampleViewButtonClicked(e: ClickEvent) {
46
+
47
+ }
48
+ }
49
+ ```
package/dist/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.Observable=class{observers=new Set;handlers=new Map;subscribe(e,s){this.observers.add(e),this.handlers.set(e,s.bind(e))}unsubscribe(e){this.observers.delete(e),this.handlers.delete(e)}unsubscribeAll(){this.observers.clear(),this.handlers.clear()}notify(e){for(const s of this.handlers.values())s(e)}};
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)}};
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":"6FAGYA,UAAyB,IAAIC,IAC7BC,SAAyC,IAAIC,IAErDC,UAAUC,EAAkBC,GACxBC,KAAKP,UAAUQ,IAAIH,GACnBE,KAAKL,SAASO,IAAIJ,EAAUC,EAAQI,KAAKL,GAC5C,CAEDM,YAAYN,GACRE,KAAKP,UAAUY,OAAOP,GACtBE,KAAKL,SAASU,OAAOP,EACxB,CAEDQ,iBACIN,KAAKP,UAAUc,QACfP,KAAKL,SAASY,OACjB,CAEDC,OAAOC,GACH,IAAK,MAAMV,KAAWC,KAAKL,SAASe,SAEhCX,EAAQU,EAEf"}
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"}
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- class s{observers=new Set;handlers=new Map;subscribe(s,e){this.observers.add(s),this.handlers.set(s,e.bind(s))}unsubscribe(s){this.observers.delete(s),this.handlers.delete(s)}unsubscribeAll(){this.observers.clear(),this.handlers.clear()}notify(s){for(const e of this.handlers.values())e(s)}}export{s as 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()}notify(value){for(const handler of this.handlers.values())handler(value)}}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,EACDC,UAAyB,IAAIC,IAC7BC,SAAyC,IAAIC,IAErDC,UAAUC,EAAkBC,GACxBC,KAAKP,UAAUQ,IAAIH,GACnBE,KAAKL,SAASO,IAAIJ,EAAUC,EAAQI,KAAKL,GAC5C,CAEDM,YAAYN,GACRE,KAAKP,UAAUY,OAAOP,GACtBE,KAAKL,SAASU,OAAOP,EACxB,CAEDQ,iBACIN,KAAKP,UAAUc,QACfP,KAAKL,SAASY,OACjB,CAEDC,OAAOC,GACH,IAAK,MAAMV,KAAWC,KAAKL,SAASe,SAEhCX,EAAQU,EAEf"}
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"}
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@nbottarini/observable",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
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",
7
- "types": "dist/index.d.ts",
7
+ "browser": "dist/esm/index.js",
8
+ "types": "dist/types/index.d.ts",
9
+ "react-native": "dist/esm/index.js",
8
10
  "author": "Nicolás Bottarini <nicolasbottarini@gmail.com>",
9
11
  "license": "MIT",
10
12
  "homepage": "https://github.com/nbottarini/observable-js#readme",
@@ -20,28 +22,35 @@
20
22
  ],
21
23
  "scripts": {
22
24
  "build": "rollup -c",
23
- "lint": "eslint . && tsc --noEmit"
25
+ "check-all": "yarn lint && yarn test",
26
+ "lint": "eslint . && tsc --noEmit",
27
+ "test": "jest"
24
28
  },
25
29
  "devDependencies": {
26
- "@babel/core": "^7.16.7",
27
- "@babel/preset-env": "^7.16.8",
28
- "@babel/preset-typescript": "^7.16.7",
29
- "@rollup/plugin-commonjs": "^22.0.2",
30
- "@rollup/plugin-node-resolve": "^13.3.0",
31
- "@rollup/plugin-typescript": "^8.3.4",
32
- "@typescript-eslint/eslint-plugin": "^5.59.0",
33
- "@typescript-eslint/parser": "^5.59.0",
34
- "eslint": "^8.38.0",
35
- "rollup": "^2.79.1",
36
- "rollup-plugin-dts": "^4.2.2",
37
- "rollup-plugin-exclude-dependencies-from-bundle": "^1.1.22",
38
- "rollup-plugin-terser": "^7.0.2",
39
- "typescript": "^4.9.5"
30
+ "@babel/core": "^7.22.10",
31
+ "@babel/preset-env": "^7.22.10",
32
+ "@babel/preset-typescript": "^7.22.5",
33
+ "@rollup/plugin-commonjs": "^25.0.3",
34
+ "@rollup/plugin-node-resolve": "^15.1.0",
35
+ "@rollup/plugin-terser": "^0.4.3",
36
+ "@rollup/plugin-typescript": "^11.1.2",
37
+ "@types/jest": "^29.5.3",
38
+ "@typescript-eslint/eslint-plugin": "^6.3.0",
39
+ "@typescript-eslint/parser": "^6.3.0",
40
+ "babel-jest": "^29.6.2",
41
+ "eslint": "^8.46.0",
42
+ "jest": "^29.6.2",
43
+ "jest-extended": "^4.0.1",
44
+ "rollup": "^3.27.2",
45
+ "rollup-plugin-dts": "^5.3.1",
46
+ "rollup-plugin-exclude-dependencies-from-bundle": "^1.1.23",
47
+ "tslib": "^2.6.1",
48
+ "typescript": "^5.1.6"
40
49
  },
41
50
  "publishConfig": {
42
51
  "registry": "https://registry.npmjs.org/"
43
52
  },
44
53
  "engines": {
45
- "node": ">= 16.0.0"
54
+ "node": ">= 18.0.0"
46
55
  }
47
56
  }
@@ -1,9 +0,0 @@
1
- export type ObserverFunc<T> = (subject: T) => void;
2
- export declare class Observable<T = void> {
3
- private observers;
4
- private handlers;
5
- subscribe(observer: object, handler: ObserverFunc<T>): void;
6
- unsubscribe(observer: object): void;
7
- unsubscribeAll(): void;
8
- notify(value?: T): void;
9
- }
@@ -1 +0,0 @@
1
- export { Observable } from './Observable';
@@ -1,9 +0,0 @@
1
- export type ObserverFunc<T> = (subject: T) => void;
2
- export declare class Observable<T = void> {
3
- private observers;
4
- private handlers;
5
- subscribe(observer: object, handler: ObserverFunc<T>): void;
6
- unsubscribe(observer: object): void;
7
- unsubscribeAll(): void;
8
- notify(value?: T): void;
9
- }
@@ -1 +0,0 @@
1
- export { Observable } from './Observable';
File without changes