@badisi/ngx-safe-subscribe 4.0.6 → 4.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@badisi/ngx-safe-subscribe",
3
- "version": "4.0.6",
3
+ "version": "4.0.7",
4
4
  "description": "Easy way to automatically unsubscribe from RxJS observables in Angular components",
5
5
  "homepage": "https://github.com/badisi/ngx-safe-subscribe",
6
6
  "license": "MIT",
@@ -26,11 +26,7 @@
26
26
  "@angular/core": ">= 14.0.0",
27
27
  "rxjs": ">= 6.0.0"
28
28
  },
29
- "module": "fesm2015/badisi-ngx-safe-subscribe.mjs",
30
- "es2020": "fesm2020/badisi-ngx-safe-subscribe.mjs",
31
- "esm2020": "esm2020/badisi-ngx-safe-subscribe.mjs",
32
- "fesm2020": "fesm2020/badisi-ngx-safe-subscribe.mjs",
33
- "fesm2015": "fesm2015/badisi-ngx-safe-subscribe.mjs",
29
+ "module": "fesm2022/badisi-ngx-safe-subscribe.mjs",
34
30
  "typings": "index.d.ts",
35
31
  "exports": {
36
32
  "./package.json": {
@@ -38,11 +34,9 @@
38
34
  },
39
35
  ".": {
40
36
  "types": "./index.d.ts",
41
- "esm2020": "./esm2020/badisi-ngx-safe-subscribe.mjs",
42
- "es2020": "./fesm2020/badisi-ngx-safe-subscribe.mjs",
43
- "es2015": "./fesm2015/badisi-ngx-safe-subscribe.mjs",
44
- "node": "./fesm2015/badisi-ngx-safe-subscribe.mjs",
45
- "default": "./fesm2020/badisi-ngx-safe-subscribe.mjs"
37
+ "esm2022": "./esm2022/badisi-ngx-safe-subscribe.mjs",
38
+ "esm": "./esm2022/badisi-ngx-safe-subscribe.mjs",
39
+ "default": "./fesm2022/badisi-ngx-safe-subscribe.mjs"
46
40
  }
47
41
  },
48
42
  "dependencies": {
@@ -1,38 +0,0 @@
1
- import { Subscription, Observable } from 'rxjs';
2
-
3
- const HAS_DECORATOR = Symbol('__safeSubscribeDecorator');
4
- const SUBSCRIPTION = Symbol('__safeSubscribeSubscription$');
5
- function SafeSubscribe(destructorName = 'ngOnDestroy') {
6
- return (classType) => {
7
- const originalDestroy = classType.prototype[destructorName];
8
- classType.prototype[destructorName] = function () {
9
- var _a;
10
- originalDestroy && originalDestroy.call(this);
11
- (_a = this[SUBSCRIPTION]) === null || _a === void 0 ? void 0 : _a.unsubscribe();
12
- this[SUBSCRIPTION] = null;
13
- };
14
- classType.prototype[HAS_DECORATOR] = true;
15
- };
16
- }
17
- function safeSubscribe(target, ...args) {
18
- const sub = this.subscribe(...args);
19
- if (target) {
20
- const hasDecorator = Object.getPrototypeOf(target)[HAS_DECORATOR];
21
- if (!hasDecorator) {
22
- throw new Error(`${target.constructor.name} class must be decorated with @SafeSubscribe() otherwise Observable<T>.safeSubscribe() will have no effect.`);
23
- }
24
- if (!target[SUBSCRIPTION]) {
25
- target[SUBSCRIPTION] = new Subscription();
26
- }
27
- target[SUBSCRIPTION].add(sub);
28
- }
29
- return sub;
30
- }
31
- Observable.prototype.safeSubscribe = safeSubscribe;
32
-
33
- /**
34
- * Generated bundle index. Do not edit.
35
- */
36
-
37
- export { SafeSubscribe, safeSubscribe };
38
- //# sourceMappingURL=badisi-ngx-safe-subscribe.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"badisi-ngx-safe-subscribe.mjs","sources":["../../ngx-safe-subscribe.ts","../../badisi-ngx-safe-subscribe.ts"],"sourcesContent":["import { Observable, Subscription } from 'rxjs';\n\nconst HAS_DECORATOR = Symbol('__safeSubscribeDecorator');\nconst SUBSCRIPTION = Symbol('__safeSubscribeSubscription$');\n\ndeclare module 'rxjs/internal/Observable' {\n interface Observable<T> {\n safeSubscribe: typeof safeSubscribe;\n }\n}\n\nexport function SafeSubscribe(destructorName ='ngOnDestroy'): ClassDecorator {\n return (classType: Function) => {\n const originalDestroy = classType.prototype[destructorName];\n classType.prototype[destructorName] = function (this: any) {\n originalDestroy && originalDestroy.call(this);\n this[SUBSCRIPTION]?.unsubscribe();\n this[SUBSCRIPTION] = null;\n }\n classType.prototype[HAS_DECORATOR] = true;\n };\n}\n\nexport function safeSubscribe<T>(this: Observable<T>, target: any, ...args: any): Subscription {\n const sub = this.subscribe(...args);\n if (target) {\n const hasDecorator = Object.getPrototypeOf(target)[HAS_DECORATOR];\n if (!hasDecorator) {\n throw new Error(`${target.constructor.name} class must be decorated with @SafeSubscribe() otherwise Observable<T>.safeSubscribe() will have no effect.`);\n }\n if (!target[SUBSCRIPTION]) {\n target[SUBSCRIPTION] = new Subscription();\n }\n target[SUBSCRIPTION].add(sub);\n }\n return sub;\n}\nObservable.prototype.safeSubscribe = safeSubscribe;\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './ngx-safe-subscribe';\n"],"names":[],"mappings":";;AAEA,MAAM,aAAa,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC;AACzD,MAAM,YAAY,GAAG,MAAM,CAAC,8BAA8B,CAAC,CAAC;AAQ5C,SAAA,aAAa,CAAC,cAAc,GAAE,aAAa,EAAA;IACvD,OAAO,CAAC,SAAmB,KAAI;QAC3B,MAAM,eAAe,GAAG,SAAS,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;AAC5D,QAAA,SAAS,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,YAAA;;AAClC,YAAA,eAAe,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9C,YAAA,CAAA,EAAA,GAAA,IAAI,CAAC,YAAY,CAAC,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,WAAW,EAAE,CAAC;AAClC,YAAA,IAAI,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;AAC9B,SAAC,CAAA;AACD,QAAA,SAAS,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;AAC9C,KAAC,CAAC;AACN,CAAC;SAEe,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