@gby/destroyable 2.0.0 → 3.0.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.
@@ -8,5 +8,5 @@
8
8
  */
9
9
  export * from './Destroyable';
10
10
  export * from "./createDestroyableSubClass";
11
- export * from "./WebDestroyable";
11
+ export * from "./DestroyableEventTarget";
12
12
  //# sourceMappingURL=index-web.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-web.d.ts","sourceRoot":"","sources":["../src/index-web.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index-web.d.ts","sourceRoot":"","sources":["../src/index-web.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC"}
package/dist/index-web.js CHANGED
@@ -1,143 +1,8 @@
1
- var y = Object.defineProperty;
2
- var c = (o, r, e) => r in o ? y(o, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[r] = e;
3
- var i = (o, r, e) => c(o, typeof r != "symbol" ? r + "" : r, e);
4
- import { a as n } from "./createDestroyableSubClass-Blnpqngp.js";
5
- import { D as p, c as _, d as m, t as x } from "./createDestroyableSubClass-Blnpqngp.js";
6
- import { EventBus as d } from "@gby/event-bus";
7
- class l extends d {
8
- constructor() {
9
- super(...arguments);
10
- /**
11
- * 引用计数
12
- * @remarks
13
- * 引用计数为 0 时,对象才会被销毁
14
- */
15
- i(this, "refCount", 0);
16
- i(this, "_isDestroyed", !1);
17
- /**
18
- * 销毁者
19
- */
20
- i(this, "_destroyers", []);
21
- }
22
- /**
23
- * 是否已经销毁
24
- */
25
- get isDestroyed() {
26
- return this._isDestroyed;
27
- }
28
- /**
29
- * 是否可以销毁
30
- */
31
- get canDestroy() {
32
- return !this.isDestroyed && this.refCount <= 0;
33
- }
34
- /**
35
- * 添加销毁者
36
- * @param fun
37
- * @returns 返回销毁者的顺序
38
- */
39
- disposeFun(e) {
40
- return this._destroyers.push(e), e;
41
- }
42
- /**
43
- * 取消销毁者函数
44
- * @param fun
45
- * @returns
46
- */
47
- cancelDisposeFun(e) {
48
- const s = this._destroyers.indexOf(e);
49
- return this._destroyers.splice(s, 1), e;
50
- }
51
- /**
52
- * 添加销毁对象
53
- * @param obj
54
- * @param sync - 表示是否使用 `obj.destroy()` 方法进行销毁;默认使用 `obj.destroyAsync()` 方法进行销毁
55
- * @returns
56
- */
57
- disposeObj(e, s) {
58
- const t = s ? function() {
59
- return e.destroy();
60
- } : function() {
61
- return e.destroyAsync();
62
- };
63
- return this.disposeFun(t), e.__destroyable_destroyer = t, e;
64
- }
65
- /**
66
- * 取消销毁者函数
67
- * @param fun
68
- * @returns
69
- */
70
- cancelDisposeObj(e) {
71
- const s = e.__destroyable_destroyer;
72
- return s && this.cancelDisposeFun(s), e;
73
- }
74
- dispose(e, s) {
75
- return typeof e == "function" ? this.disposeFun(e) : this.disposeObj(e, s);
76
- }
77
- cancelDispose(e) {
78
- return typeof e == "function" ? this.cancelDisposeFun(e) : this.cancelDisposeObj(e);
79
- }
80
- /**
81
- * 自己的销毁方法
82
- * @remarks
83
- * 子类根据需要进行重载
84
- */
85
- destroyThis() {
86
- }
87
- /**
88
- * 销毁
89
- */
90
- destroy() {
91
- if (!this.canDestroy) return this.isDestroyed;
92
- let e = this._destroyers.length;
93
- for (; --e >= 0; ) {
94
- const s = this._destroyers[e];
95
- try {
96
- s();
97
- } catch (t) {
98
- console.error("销毁函数在同步销毁时出错", this, s, t);
99
- }
100
- }
101
- this._destroyers.length = 0;
102
- try {
103
- this.destroyThis();
104
- } catch (s) {
105
- console.error("destroyThis 在异步销毁时出错", this, s);
106
- }
107
- return n(this), !0;
108
- }
109
- /**
110
- * 异步销毁
111
- * @remarks
112
- * 会依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
113
- */
114
- async destroyAsync() {
115
- if (!this.canDestroy) return this.isDestroyed;
116
- let e = this._destroyers.length;
117
- for (; --e >= 0; ) {
118
- const s = this._destroyers[e];
119
- try {
120
- const t = s();
121
- t && t instanceof Promise && await t;
122
- } catch (t) {
123
- console.error("销毁函数在异步销毁时出错", this, s, t);
124
- }
125
- }
126
- this._destroyers.length = 0;
127
- try {
128
- const s = this.destroyThis();
129
- s && s instanceof Promise && await s;
130
- } catch (s) {
131
- console.error("destroyThis 在异步销毁时出错", this, s);
132
- }
133
- return n(this), !0;
134
- }
135
- }
1
+ import { D as t, c as a, a as r, d as o, t as y } from "./DestroyableEventTarget-3_XyRRfB.js";
136
2
  export {
137
- p as Destroyable,
138
- l as WebDestroyable,
139
- _ as createDestroyableSubClass,
140
- n as destroyDestroyable,
141
- m as destroyObject,
142
- x as throwOnDestroyed
3
+ t as DestroyableEventTarget,
4
+ a as createDestroyableSubClass,
5
+ r as destroyDestroyable,
6
+ o as destroyObject,
7
+ y as throwOnDestroyed
143
8
  };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./createDestroyableSubClass-Ck7j3oA0.cjs"),t=require("@gby/event-bus"),s=require("node:events"),r=e.createDestroyableSubClass(t.EventBus),o=e.createDestroyableSubClass(s.EventEmitter);exports.Destroyable=e.Destroyable;exports.createDestroyableSubClass=e.createDestroyableSubClass;exports.destroyDestroyable=e.destroyDestroyable;exports.destroyObject=e.destroyObject;exports.throwOnDestroyed=e.throwOnDestroyed;exports.NodeDestroyable=o;exports.WebDestroyable=r;
1
+ "use strict";var y=Object.defineProperty;var d=(i,r,e)=>r in i?y(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e;var n=(i,r,e)=>d(i,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./DestroyableEventTarget-B26KR0Ul.cjs"),c=require("node:events");class h extends c.EventEmitter{constructor(){super(...arguments);n(this,"refCount",0);n(this,"_isDestroyed",!1);n(this,"_destroyers",[])}get isDestroyed(){return this._isDestroyed}get canDestroy(){return!this.isDestroyed&&this.refCount<=0}disposeFun(e){return this._destroyers.push(e),e}cancelDisposeFun(e){const t=this._destroyers.indexOf(e);return this._destroyers.splice(t,1),e}disposeObj(e,t){const s=t?function(){return e.destroy()}:function(){return e.destroyAsync()};return this.disposeFun(s),e.__destroyable_destroyer=s,e}cancelDisposeObj(e){const t=e.__destroyable_destroyer;return t&&this.cancelDisposeFun(t),e}dispose(e,t){return typeof e=="function"?this.disposeFun(e):this.disposeObj(e,t)}cancelDispose(e){return typeof e=="function"?this.cancelDisposeFun(e):this.cancelDisposeObj(e)}destroyThis(){}destroy(){if(!this.canDestroy)return this.isDestroyed;let e=this._destroyers.length;for(;--e>=0;){const t=this._destroyers[e];try{t()}catch(s){console.error("销毁函数在同步销毁时出错",this,t,s)}}this._destroyers.length=0;try{this.destroyThis()}catch(t){console.error("destroyThis 在异步销毁时出错",this,t)}return o.destroyDestroyable(this),!0}async destroyAsync(){if(!this.canDestroy)return this.isDestroyed;let e=this._destroyers.length;for(;--e>=0;){const t=this._destroyers[e];try{const s=t();s&&s instanceof Promise&&await s}catch(s){console.error("销毁函数在异步销毁时出错",this,t,s)}}this._destroyers.length=0;try{const t=this.destroyThis();t&&t instanceof Promise&&await t}catch(t){console.error("destroyThis 在异步销毁时出错",this,t)}return o.destroyDestroyable(this),!0}}exports.DestroyableEventTarget=o.DestroyableEventTarget;exports.createDestroyableSubClass=o.createDestroyableSubClass;exports.destroyDestroyable=o.destroyDestroyable;exports.destroyObject=o.destroyObject;exports.throwOnDestroyed=o.throwOnDestroyed;exports.DestroyableEventEmitter=h;
package/dist/index.d.ts CHANGED
@@ -8,5 +8,6 @@
8
8
  */
9
9
  export * from './Destroyable';
10
10
  export * from "./createDestroyableSubClass";
11
- export * from "./DestroyableSub";
11
+ export * from "./DestroyableEventTarget";
12
+ export * from "./DestroyableEventEmitter";
12
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC"}
package/dist/index.js CHANGED
@@ -1,14 +1,143 @@
1
- import { c as e } from "./createDestroyableSubClass-Blnpqngp.js";
2
- import { D as l, a as c, d, t as n } from "./createDestroyableSubClass-Blnpqngp.js";
3
- import { EventBus as t } from "@gby/event-bus";
4
- import { EventEmitter as o } from "node:events";
5
- const b = e(t), m = e(o);
1
+ var y = Object.defineProperty;
2
+ var c = (o, r, e) => r in o ? y(o, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[r] = e;
3
+ var i = (o, r, e) => c(o, typeof r != "symbol" ? r + "" : r, e);
4
+ import { a as n } from "./DestroyableEventTarget-3_XyRRfB.js";
5
+ import { D as p, c as _, d as m, t as g } from "./DestroyableEventTarget-3_XyRRfB.js";
6
+ import { EventEmitter as d } from "node:events";
7
+ class u extends d {
8
+ constructor() {
9
+ super(...arguments);
10
+ /**
11
+ * 引用计数
12
+ * @remarks
13
+ * 引用计数为 0 时,对象才会被销毁
14
+ */
15
+ i(this, "refCount", 0);
16
+ i(this, "_isDestroyed", !1);
17
+ /**
18
+ * 销毁者
19
+ */
20
+ i(this, "_destroyers", []);
21
+ }
22
+ /**
23
+ * 是否已经销毁
24
+ */
25
+ get isDestroyed() {
26
+ return this._isDestroyed;
27
+ }
28
+ /**
29
+ * 是否可以销毁
30
+ */
31
+ get canDestroy() {
32
+ return !this.isDestroyed && this.refCount <= 0;
33
+ }
34
+ /**
35
+ * 添加销毁者
36
+ * @param fun
37
+ * @returns 返回销毁者的顺序
38
+ */
39
+ disposeFun(e) {
40
+ return this._destroyers.push(e), e;
41
+ }
42
+ /**
43
+ * 取消销毁者函数
44
+ * @param fun
45
+ * @returns
46
+ */
47
+ cancelDisposeFun(e) {
48
+ const s = this._destroyers.indexOf(e);
49
+ return this._destroyers.splice(s, 1), e;
50
+ }
51
+ /**
52
+ * 添加销毁对象
53
+ * @param obj
54
+ * @param sync - 表示是否使用 `obj.destroy()` 方法进行销毁;默认使用 `obj.destroyAsync()` 方法进行销毁
55
+ * @returns
56
+ */
57
+ disposeObj(e, s) {
58
+ const t = s ? function() {
59
+ return e.destroy();
60
+ } : function() {
61
+ return e.destroyAsync();
62
+ };
63
+ return this.disposeFun(t), e.__destroyable_destroyer = t, e;
64
+ }
65
+ /**
66
+ * 取消销毁者函数
67
+ * @param fun
68
+ * @returns
69
+ */
70
+ cancelDisposeObj(e) {
71
+ const s = e.__destroyable_destroyer;
72
+ return s && this.cancelDisposeFun(s), e;
73
+ }
74
+ dispose(e, s) {
75
+ return typeof e == "function" ? this.disposeFun(e) : this.disposeObj(e, s);
76
+ }
77
+ cancelDispose(e) {
78
+ return typeof e == "function" ? this.cancelDisposeFun(e) : this.cancelDisposeObj(e);
79
+ }
80
+ /**
81
+ * 自己的销毁方法
82
+ * @remarks
83
+ * 子类根据需要进行重载
84
+ */
85
+ destroyThis() {
86
+ }
87
+ /**
88
+ * 销毁
89
+ */
90
+ destroy() {
91
+ if (!this.canDestroy) return this.isDestroyed;
92
+ let e = this._destroyers.length;
93
+ for (; --e >= 0; ) {
94
+ const s = this._destroyers[e];
95
+ try {
96
+ s();
97
+ } catch (t) {
98
+ console.error("销毁函数在同步销毁时出错", this, s, t);
99
+ }
100
+ }
101
+ this._destroyers.length = 0;
102
+ try {
103
+ this.destroyThis();
104
+ } catch (s) {
105
+ console.error("destroyThis 在异步销毁时出错", this, s);
106
+ }
107
+ return n(this), !0;
108
+ }
109
+ /**
110
+ * 异步销毁
111
+ * @remarks
112
+ * 会依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
113
+ */
114
+ async destroyAsync() {
115
+ if (!this.canDestroy) return this.isDestroyed;
116
+ let e = this._destroyers.length;
117
+ for (; --e >= 0; ) {
118
+ const s = this._destroyers[e];
119
+ try {
120
+ const t = s();
121
+ t && t instanceof Promise && await t;
122
+ } catch (t) {
123
+ console.error("销毁函数在异步销毁时出错", this, s, t);
124
+ }
125
+ }
126
+ this._destroyers.length = 0;
127
+ try {
128
+ const s = this.destroyThis();
129
+ s && s instanceof Promise && await s;
130
+ } catch (s) {
131
+ console.error("destroyThis 在异步销毁时出错", this, s);
132
+ }
133
+ return n(this), !0;
134
+ }
135
+ }
6
136
  export {
7
- l as Destroyable,
8
- m as NodeDestroyable,
9
- b as WebDestroyable,
10
- e as createDestroyableSubClass,
11
- c as destroyDestroyable,
12
- d as destroyObject,
13
- n as throwOnDestroyed
137
+ u as DestroyableEventEmitter,
138
+ p as DestroyableEventTarget,
139
+ _ as createDestroyableSubClass,
140
+ n as destroyDestroyable,
141
+ m as destroyObject,
142
+ g as throwOnDestroyed
14
143
  };
package/package.json CHANGED
@@ -1,16 +1,11 @@
1
1
  {
2
2
  "name": "@gby/destroyable",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "@gby/destroyable 提供了用于构建可销毁对象的类的基类,用于使得地管理可销毁对象的生命周期",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {
9
- "node": {
10
- "require": "./dist/index-node.cjs",
11
- "types": "./dist/index-node.d.ts",
12
- "import": "./dist/index-node.js"
13
- },
14
9
  "browser": {
15
10
  "require": "./dist/index-web.cjs",
16
11
  "types": "./dist/index-web.d.ts",
@@ -18,8 +13,7 @@
18
13
  },
19
14
  "require": "./dist/index.cjs",
20
15
  "types": "./dist/index.d.ts",
21
- "import": "./dist/index.js",
22
- "default": "./dist/index.js"
16
+ "import": "./dist/index.js"
23
17
  },
24
18
  "type": "module",
25
19
  "sideEffects": false,
@@ -1,83 +0,0 @@
1
- import { EventBus } from "@gby/event-bus";
2
- import { EventEmitter } from "node:events";
3
- /**
4
- * WebDestroyable 类对象
5
- */
6
- export declare const WebDestroyable: {
7
- new (...args: any): {
8
- refCount: number;
9
- readonly isDestroyed: boolean;
10
- _isDestroyed: boolean;
11
- readonly canDestroy: boolean;
12
- _destroyers: import("./Destroyable").FunDestroyer[];
13
- disposeFun<T extends import("./Destroyable").FunDestroyer>(fun: T): T;
14
- cancelDisposeFun<T extends import("./Destroyable").FunDestroyer>(fun: T): T;
15
- disposeObj<T extends /*elided*/ any>(obj: T, sync?: boolean): T;
16
- cancelDisposeObj<T extends /*elided*/ any>(obj: T): T;
17
- dispose<T extends import("./Destroyable").FunDestroyer>(fun: T): T;
18
- dispose<T extends /*elided*/ any>(obj: T, asyncDestroy?: boolean): T;
19
- dispose<T extends import("./Destroyable").FunDestroyer | /*elided*/ any>(objOrFun: T, asyncDestroy?: boolean): T;
20
- cancelDispose<T extends import("./Destroyable").FunDestroyer>(fun: T): T;
21
- cancelDispose<T extends /*elided*/ any>(obj: T): T;
22
- cancelDispose<T extends import("./Destroyable").FunDestroyer | /*elided*/ any>(objOrFun: T): T;
23
- destroyThis(): void;
24
- destroy(): boolean;
25
- destroyAsync(): Promise<boolean>;
26
- constructor: Function;
27
- toString(): string;
28
- toLocaleString(): string;
29
- valueOf(): Object;
30
- hasOwnProperty(v: PropertyKey): boolean;
31
- isPrototypeOf(v: Object): boolean;
32
- propertyIsEnumerable(v: PropertyKey): boolean;
33
- };
34
- } & typeof EventBus;
35
- /**
36
- * WebDestroyable 类的类型
37
- */
38
- export type WebDestroyableClass = typeof WebDestroyable;
39
- /**
40
- * WebDestroyable 实例的类型
41
- */
42
- export type WebDestroyable = InstanceType<WebDestroyableClass>;
43
- /**
44
- * NodeDestroyable 类对象
45
- */
46
- export declare const NodeDestroyable: {
47
- new (...args: any): {
48
- refCount: number;
49
- readonly isDestroyed: boolean;
50
- _isDestroyed: boolean;
51
- readonly canDestroy: boolean;
52
- _destroyers: import("./Destroyable").FunDestroyer[];
53
- disposeFun<T extends import("./Destroyable").FunDestroyer>(fun: T): T;
54
- cancelDisposeFun<T extends import("./Destroyable").FunDestroyer>(fun: T): T;
55
- disposeObj<T extends /*elided*/ any>(obj: T, sync?: boolean): T;
56
- cancelDisposeObj<T extends /*elided*/ any>(obj: T): T;
57
- dispose<T extends import("./Destroyable").FunDestroyer>(fun: T): T;
58
- dispose<T extends /*elided*/ any>(obj: T, asyncDestroy?: boolean): T;
59
- dispose<T extends import("./Destroyable").FunDestroyer | /*elided*/ any>(objOrFun: T, asyncDestroy?: boolean): T;
60
- cancelDispose<T extends import("./Destroyable").FunDestroyer>(fun: T): T;
61
- cancelDispose<T extends /*elided*/ any>(obj: T): T;
62
- cancelDispose<T extends import("./Destroyable").FunDestroyer | /*elided*/ any>(objOrFun: T): T;
63
- destroyThis(): void;
64
- destroy(): boolean;
65
- destroyAsync(): Promise<boolean>;
66
- constructor: Function;
67
- toString(): string;
68
- toLocaleString(): string;
69
- valueOf(): Object;
70
- hasOwnProperty(v: PropertyKey): boolean;
71
- isPrototypeOf(v: Object): boolean;
72
- propertyIsEnumerable(v: PropertyKey): boolean;
73
- };
74
- } & typeof EventEmitter;
75
- /**
76
- * NodeDestroyable 类的类型
77
- */
78
- export type NodeDestroyableClass = typeof NodeDestroyable;
79
- /**
80
- * NodeDestroyable 实例的类型
81
- */
82
- export type NodeDestroyable = InstanceType<NodeDestroyableClass>;
83
- //# sourceMappingURL=DestroyableSub.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DestroyableSub.d.ts","sourceRoot":"","sources":["../src/DestroyableSub.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,gBA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;;;OAIG;IACG,YAAY;CA6BrB"}
@@ -1 +0,0 @@
1
- "use strict";var u=Object.defineProperty;var a=(i,e,s)=>e in i?u(i,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[e]=s;var y=(i,e,s)=>a(i,typeof e!="symbol"?e+"":e,s);class h{constructor(){y(this,"refCount",0);y(this,"_isDestroyed",!1);y(this,"_destroyers",[])}get isDestroyed(){return this._isDestroyed}get canDestroy(){return!this.isDestroyed&&this.refCount<=0}disposeFun(e){return this._destroyers.push(e),e}cancelDisposeFun(e){const s=this._destroyers.indexOf(e);return this._destroyers.splice(s,1),e}disposeObj(e,s){const o=s?function(){return e.destroy()}:function(){return e.destroyAsync()};return this.disposeFun(o),e.__destroyable_destroyer=o,e}cancelDisposeObj(e){const s=e.__destroyable_destroyer;return s&&this.cancelDisposeFun(s),e}dispose(e,s){return typeof e=="function"?this.disposeFun(e):this.disposeObj(e,s)}cancelDispose(e){return typeof e=="function"?this.cancelDisposeFun(e):this.cancelDisposeObj(e)}destroyThis(){}destroy(){if(!this.canDestroy)return this.isDestroyed;let e=this._destroyers.length;for(;--e>=0;){const s=this._destroyers[e];try{s()}catch(o){console.error("销毁函数在同步销毁时出错",this,s,o)}}this._destroyers.length=0;try{this.destroyThis()}catch(s){console.error("destroyThis 在异步销毁时出错",this,s)}return c(this),!0}async destroyAsync(){if(!this.canDestroy)return this.isDestroyed;let e=this._destroyers.length;for(;--e>=0;){const s=this._destroyers[e];try{const o=s();o&&o instanceof Promise&&await o}catch(o){console.error("销毁函数在异步销毁时出错",this,s,o)}}this._destroyers.length=0;try{const s=this.destroyThis();s&&s instanceof Promise&&await s}catch(s){console.error("destroyThis 在异步销毁时出错",this,s)}return c(this),!0}}function d(){throw"已销毁"}function l(i){for(var e in i)typeof i[e]=="function"&&(i[e]=d);return i._isDestroyed=!0,!0}function c(i){for(var e in i)!(e in h.prototype)&&typeof i[e]=="function"&&(i[e]=d);return i._isDestroyed=!0,!0}function f(i){class e extends i{constructor(){super(...arguments);y(this,"refCount",0);y(this,"_isDestroyed",!1);y(this,"_destroyers",[])}get isDestroyed(){return this._isDestroyed}get canDestroy(){return!this.isDestroyed&&this.refCount<=0}disposeFun(t){return this._destroyers.push(t),t}cancelDisposeFun(t){const r=this._destroyers.indexOf(t);return this._destroyers.splice(r,1),t}disposeObj(t,r){const n=r?function(){return t.destroy()}:function(){return t.destroyAsync()};return this.disposeFun(n),t.__destroyable_destroyer=n,t}cancelDisposeObj(t){const r=t.__destroyable_destroyer;return r&&this.cancelDisposeFun(r),t}dispose(t,r){return typeof t=="function"?this.disposeFun(t):this.disposeObj(t,r)}cancelDispose(t){return typeof t=="function"?this.cancelDisposeFun(t):this.cancelDisposeObj(t)}destroyThis(){}destroy(){if(!this.canDestroy)return this.isDestroyed;let t=this._destroyers.length;for(;--t>=0;){const r=this._destroyers[t];try{r()}catch(n){console.error("销毁函数在同步销毁时出错",this,r,n)}}this._destroyers.length=0;try{this.destroyThis()}catch(r){console.error("destroyThis 在异步销毁时出错",this,r)}return c(this),!0}async destroyAsync(){if(!this.canDestroy)return this.isDestroyed;let t=this._destroyers.length;for(;--t>=0;){const r=this._destroyers[t];try{const n=r();n&&n instanceof Promise&&await n}catch(n){console.error("销毁函数在异步销毁时出错",this,r,n)}}this._destroyers.length=0;try{const r=this.destroyThis();r&&r instanceof Promise&&await r}catch(r){console.error("destroyThis 在异步销毁时出错",this,r)}return c(this),!0}}return e}exports.Destroyable=h;exports.createDestroyableSubClass=f;exports.destroyDestroyable=c;exports.destroyObject=l;exports.throwOnDestroyed=d;
@@ -1 +0,0 @@
1
- "use strict";var y=Object.defineProperty;var d=(i,r,e)=>r in i?y(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e;var n=(i,r,e)=>d(i,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./createDestroyableSubClass-Ck7j3oA0.cjs"),c=require("node:events");class h extends c.EventEmitter{constructor(){super(...arguments);n(this,"refCount",0);n(this,"_isDestroyed",!1);n(this,"_destroyers",[])}get isDestroyed(){return this._isDestroyed}get canDestroy(){return!this.isDestroyed&&this.refCount<=0}disposeFun(e){return this._destroyers.push(e),e}cancelDisposeFun(e){const s=this._destroyers.indexOf(e);return this._destroyers.splice(s,1),e}disposeObj(e,s){const t=s?function(){return e.destroy()}:function(){return e.destroyAsync()};return this.disposeFun(t),e.__destroyable_destroyer=t,e}cancelDisposeObj(e){const s=e.__destroyable_destroyer;return s&&this.cancelDisposeFun(s),e}dispose(e,s){return typeof e=="function"?this.disposeFun(e):this.disposeObj(e,s)}cancelDispose(e){return typeof e=="function"?this.cancelDisposeFun(e):this.cancelDisposeObj(e)}destroyThis(){}destroy(){if(!this.canDestroy)return this.isDestroyed;let e=this._destroyers.length;for(;--e>=0;){const s=this._destroyers[e];try{s()}catch(t){console.error("销毁函数在同步销毁时出错",this,s,t)}}this._destroyers.length=0;try{this.destroyThis()}catch(s){console.error("destroyThis 在异步销毁时出错",this,s)}return o.destroyDestroyable(this),!0}async destroyAsync(){if(!this.canDestroy)return this.isDestroyed;let e=this._destroyers.length;for(;--e>=0;){const s=this._destroyers[e];try{const t=s();t&&t instanceof Promise&&await t}catch(t){console.error("销毁函数在异步销毁时出错",this,s,t)}}this._destroyers.length=0;try{const s=this.destroyThis();s&&s instanceof Promise&&await s}catch(s){console.error("destroyThis 在异步销毁时出错",this,s)}return o.destroyDestroyable(this),!0}}exports.Destroyable=o.Destroyable;exports.createDestroyableSubClass=o.createDestroyableSubClass;exports.destroyDestroyable=o.destroyDestroyable;exports.destroyObject=o.destroyObject;exports.throwOnDestroyed=o.throwOnDestroyed;exports.NodeDestroyable=h;
@@ -1,12 +0,0 @@
1
- /**
2
- * 可销毁的
3
- *
4
- * @remarks
5
- * @gby/destroyable 提供了用于构建可销毁对象的类的基类,用于使得地管理可销毁对象的生命周期
6
- *
7
- * @packageDocumentation
8
- */
9
- export * from './Destroyable';
10
- export * from "./createDestroyableSubClass";
11
- export * from "./NodeDestroyable";
12
- //# sourceMappingURL=index-node.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-node.d.ts","sourceRoot":"","sources":["../src/index-node.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,mBAAmB,CAAA"}
@@ -1,143 +0,0 @@
1
- var y = Object.defineProperty;
2
- var d = (o, r, e) => r in o ? y(o, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[r] = e;
3
- var i = (o, r, e) => d(o, typeof r != "symbol" ? r + "" : r, e);
4
- import { a as n } from "./createDestroyableSubClass-Blnpqngp.js";
5
- import { D as p, c as _, d as m, t as x } from "./createDestroyableSubClass-Blnpqngp.js";
6
- import { EventEmitter as c } from "node:events";
7
- class u extends c {
8
- constructor() {
9
- super(...arguments);
10
- /**
11
- * 引用计数
12
- * @remarks
13
- * 引用计数为 0 时,对象才会被销毁
14
- */
15
- i(this, "refCount", 0);
16
- i(this, "_isDestroyed", !1);
17
- /**
18
- * 销毁者
19
- */
20
- i(this, "_destroyers", []);
21
- }
22
- /**
23
- * 是否已经销毁
24
- */
25
- get isDestroyed() {
26
- return this._isDestroyed;
27
- }
28
- /**
29
- * 是否可以销毁
30
- */
31
- get canDestroy() {
32
- return !this.isDestroyed && this.refCount <= 0;
33
- }
34
- /**
35
- * 添加销毁者
36
- * @param fun
37
- * @returns 返回销毁者的顺序
38
- */
39
- disposeFun(e) {
40
- return this._destroyers.push(e), e;
41
- }
42
- /**
43
- * 取消销毁者函数
44
- * @param fun
45
- * @returns
46
- */
47
- cancelDisposeFun(e) {
48
- const s = this._destroyers.indexOf(e);
49
- return this._destroyers.splice(s, 1), e;
50
- }
51
- /**
52
- * 添加销毁对象
53
- * @param obj
54
- * @param sync - 表示是否使用 `obj.destroy()` 方法进行销毁;默认使用 `obj.destroyAsync()` 方法进行销毁
55
- * @returns
56
- */
57
- disposeObj(e, s) {
58
- const t = s ? function() {
59
- return e.destroy();
60
- } : function() {
61
- return e.destroyAsync();
62
- };
63
- return this.disposeFun(t), e.__destroyable_destroyer = t, e;
64
- }
65
- /**
66
- * 取消销毁者函数
67
- * @param fun
68
- * @returns
69
- */
70
- cancelDisposeObj(e) {
71
- const s = e.__destroyable_destroyer;
72
- return s && this.cancelDisposeFun(s), e;
73
- }
74
- dispose(e, s) {
75
- return typeof e == "function" ? this.disposeFun(e) : this.disposeObj(e, s);
76
- }
77
- cancelDispose(e) {
78
- return typeof e == "function" ? this.cancelDisposeFun(e) : this.cancelDisposeObj(e);
79
- }
80
- /**
81
- * 自己的销毁方法
82
- * @remarks
83
- * 子类根据需要进行重载
84
- */
85
- destroyThis() {
86
- }
87
- /**
88
- * 销毁
89
- */
90
- destroy() {
91
- if (!this.canDestroy) return this.isDestroyed;
92
- let e = this._destroyers.length;
93
- for (; --e >= 0; ) {
94
- const s = this._destroyers[e];
95
- try {
96
- s();
97
- } catch (t) {
98
- console.error("销毁函数在同步销毁时出错", this, s, t);
99
- }
100
- }
101
- this._destroyers.length = 0;
102
- try {
103
- this.destroyThis();
104
- } catch (s) {
105
- console.error("destroyThis 在异步销毁时出错", this, s);
106
- }
107
- return n(this), !0;
108
- }
109
- /**
110
- * 异步销毁
111
- * @remarks
112
- * 会依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
113
- */
114
- async destroyAsync() {
115
- if (!this.canDestroy) return this.isDestroyed;
116
- let e = this._destroyers.length;
117
- for (; --e >= 0; ) {
118
- const s = this._destroyers[e];
119
- try {
120
- const t = s();
121
- t && t instanceof Promise && await t;
122
- } catch (t) {
123
- console.error("销毁函数在异步销毁时出错", this, s, t);
124
- }
125
- }
126
- this._destroyers.length = 0;
127
- try {
128
- const s = this.destroyThis();
129
- s && s instanceof Promise && await s;
130
- } catch (s) {
131
- console.error("destroyThis 在异步销毁时出错", this, s);
132
- }
133
- return n(this), !0;
134
- }
135
- }
136
- export {
137
- p as Destroyable,
138
- u as NodeDestroyable,
139
- _ as createDestroyableSubClass,
140
- n as destroyDestroyable,
141
- m as destroyObject,
142
- x as throwOnDestroyed
143
- };