@gby/destroyable 1.0.2 → 2.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.
- package/dist/Destroyable.d.ts +96 -275
- package/dist/Destroyable.d.ts.map +1 -1
- package/dist/DestroyableSub.d.ts +8 -4
- package/dist/DestroyableSub.d.ts.map +1 -1
- package/dist/NodeDestroyable.d.ts +80 -0
- package/dist/NodeDestroyable.d.ts.map +1 -0
- package/dist/WebDestroyable.d.ts +78 -0
- package/dist/WebDestroyable.d.ts.map +1 -0
- package/dist/createDestroyableSubClass-Blnpqngp.js +283 -0
- package/dist/createDestroyableSubClass-Ck7j3oA0.cjs +1 -0
- package/dist/createDestroyableSubClass.d.ts +12 -2
- package/dist/createDestroyableSubClass.d.ts.map +1 -1
- package/dist/index-node.cjs +1 -0
- package/dist/index-node.d.ts +12 -0
- package/dist/index-node.d.ts.map +1 -0
- package/dist/index-node.js +143 -0
- package/dist/index-web.cjs +1 -0
- package/dist/index-web.d.ts +12 -0
- package/dist/index-web.d.ts.map +1 -0
- package/dist/index-web.js +143 -0
- package/dist/index.cjs +1 -0
- package/dist/index.js +11 -226
- package/package.json +15 -4
- package/dist/index.umd.cjs +0 -1
- package/dist/tsdoc-metadata.json +0 -11
package/dist/index.js
CHANGED
|
@@ -1,229 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
class _ {
|
|
7
|
-
constructor() {
|
|
8
|
-
o(this, "_isDestroyed", !1);
|
|
9
|
-
/**
|
|
10
|
-
* 销毁者
|
|
11
|
-
*/
|
|
12
|
-
o(this, "_destroyers", []);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* 是否已经销毁
|
|
16
|
-
*/
|
|
17
|
-
get isDestroyed() {
|
|
18
|
-
return this._isDestroyed;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* 添加销毁者
|
|
22
|
-
* @param fun
|
|
23
|
-
* @returns 返回销毁者的顺序
|
|
24
|
-
*/
|
|
25
|
-
disposeFun(e) {
|
|
26
|
-
return this._destroyers.push(e), e;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* 取消销毁者函数
|
|
30
|
-
* @param fun
|
|
31
|
-
* @returns
|
|
32
|
-
*/
|
|
33
|
-
cancelDisposeFun(e) {
|
|
34
|
-
const r = this._destroyers.indexOf(e);
|
|
35
|
-
return this._destroyers.splice(r, 1), e;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* 添加销毁对象
|
|
39
|
-
* @param obj
|
|
40
|
-
* @param sync - 表示是否使用 `obj.destroy()` 方法进行销毁;默认使用 `obj.destroyAsync()` 方法进行销毁
|
|
41
|
-
* @returns
|
|
42
|
-
*/
|
|
43
|
-
disposeObj(e, r) {
|
|
44
|
-
const n = r ? function() {
|
|
45
|
-
return e.destroy();
|
|
46
|
-
} : function() {
|
|
47
|
-
return e.destroyAsync();
|
|
48
|
-
};
|
|
49
|
-
return this.disposeFun(n), e.__destroyable_destroyer = n, e;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* 取消销毁者函数
|
|
53
|
-
* @param fun
|
|
54
|
-
* @returns
|
|
55
|
-
*/
|
|
56
|
-
cancelDisposeObj(e) {
|
|
57
|
-
const r = e.__destroyable_destroyer;
|
|
58
|
-
return r && this.cancelDisposeFun(r), e;
|
|
59
|
-
}
|
|
60
|
-
dispose(e, r) {
|
|
61
|
-
return typeof e == "function" ? this.disposeFun(e) : this.disposeObj(e, r);
|
|
62
|
-
}
|
|
63
|
-
cancelDispose(e) {
|
|
64
|
-
return typeof e == "function" ? this.cancelDisposeFun(e) : this.cancelDisposeObj(e);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* 自己的销毁方法
|
|
68
|
-
* @remarks
|
|
69
|
-
* 子类根据需要进行重载
|
|
70
|
-
*/
|
|
71
|
-
destroyThis() {
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* 销毁
|
|
75
|
-
*/
|
|
76
|
-
destroy() {
|
|
77
|
-
if (this.isDestroyed) return !0;
|
|
78
|
-
let e = this._destroyers.length;
|
|
79
|
-
for (; --e >= 0; )
|
|
80
|
-
try {
|
|
81
|
-
this._destroyers[e]();
|
|
82
|
-
} catch {
|
|
83
|
-
}
|
|
84
|
-
this._destroyers.length = 0, this.destroyThis(), u(this);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* 异步销毁
|
|
88
|
-
* @remarks
|
|
89
|
-
* 会依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
|
|
90
|
-
*/
|
|
91
|
-
async destroyAsync() {
|
|
92
|
-
if (this.isDestroyed) return !0;
|
|
93
|
-
let e = this._destroyers.length;
|
|
94
|
-
for (; --e >= 0; )
|
|
95
|
-
try {
|
|
96
|
-
await this._destroyers[e]();
|
|
97
|
-
} catch {
|
|
98
|
-
}
|
|
99
|
-
this._destroyers.length = 0, await this.destroyThis(), u(this);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function y() {
|
|
103
|
-
throw "已销毁";
|
|
104
|
-
}
|
|
105
|
-
function x(t) {
|
|
106
|
-
for (var e in t)
|
|
107
|
-
typeof t[e] == "function" && (t[e] = y);
|
|
108
|
-
return t._isDestroyed = !0, !0;
|
|
109
|
-
}
|
|
110
|
-
function u(t) {
|
|
111
|
-
for (var e in t)
|
|
112
|
-
!(e in _.prototype) && typeof t[e] == "function" && (t[e] = y);
|
|
113
|
-
return t._isDestroyed = !0, !0;
|
|
114
|
-
}
|
|
115
|
-
function c(t) {
|
|
116
|
-
class e extends t {
|
|
117
|
-
constructor() {
|
|
118
|
-
super(...arguments);
|
|
119
|
-
o(this, "_isDestroyed", !1);
|
|
120
|
-
/**
|
|
121
|
-
* 销毁者
|
|
122
|
-
*/
|
|
123
|
-
o(this, "_destroyers", []);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* 是否已经销毁
|
|
127
|
-
*/
|
|
128
|
-
get isDestroyed() {
|
|
129
|
-
return this._isDestroyed;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* 添加销毁者
|
|
133
|
-
* @param fun
|
|
134
|
-
* @returns 返回销毁者的顺序
|
|
135
|
-
*/
|
|
136
|
-
disposeFun(s) {
|
|
137
|
-
return this._destroyers.push(s), s;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* 取消销毁者函数
|
|
141
|
-
* @param fun
|
|
142
|
-
* @returns
|
|
143
|
-
*/
|
|
144
|
-
cancelDisposeFun(s) {
|
|
145
|
-
const i = this._destroyers.indexOf(s);
|
|
146
|
-
return this._destroyers.splice(i, 1), s;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* 添加销毁对象
|
|
150
|
-
* @param obj
|
|
151
|
-
* @param sync - 表示是否使用 `obj.destroy()` 方法进行销毁;默认使用 `obj.destroyAsync()` 方法进行销毁
|
|
152
|
-
* @returns
|
|
153
|
-
*/
|
|
154
|
-
disposeObj(s, i) {
|
|
155
|
-
const h = i ? function() {
|
|
156
|
-
return s.destroy();
|
|
157
|
-
} : function() {
|
|
158
|
-
return s.destroyAsync();
|
|
159
|
-
};
|
|
160
|
-
return this.disposeFun(h), s.__destroyable_destroyer = h, s;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* 取消销毁者函数
|
|
164
|
-
* @param fun
|
|
165
|
-
* @returns
|
|
166
|
-
*/
|
|
167
|
-
cancelDisposeObj(s) {
|
|
168
|
-
const i = s.__destroyable_destroyer;
|
|
169
|
-
return i && this.cancelDisposeFun(i), s;
|
|
170
|
-
}
|
|
171
|
-
dispose(s, i) {
|
|
172
|
-
return typeof s == "function" ? this.disposeFun(s) : this.disposeObj(s, i);
|
|
173
|
-
}
|
|
174
|
-
cancelDispose(s) {
|
|
175
|
-
return typeof s == "function" ? this.cancelDisposeFun(s) : this.cancelDisposeObj(s);
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* 自己的销毁方法
|
|
179
|
-
* @remarks
|
|
180
|
-
* 子类根据需要进行重载
|
|
181
|
-
*/
|
|
182
|
-
destroyThis() {
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* 销毁
|
|
186
|
-
*/
|
|
187
|
-
destroy() {
|
|
188
|
-
if (this.isDestroyed) return !0;
|
|
189
|
-
let s = this._destroyers.length;
|
|
190
|
-
for (; --s >= 0; )
|
|
191
|
-
try {
|
|
192
|
-
this._destroyers[s]();
|
|
193
|
-
} catch {
|
|
194
|
-
}
|
|
195
|
-
this._destroyers.length = 0, this.destroyThis(), r(this);
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* 异步销毁
|
|
199
|
-
* @remarks
|
|
200
|
-
* 会依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
|
|
201
|
-
*/
|
|
202
|
-
async destroyAsync() {
|
|
203
|
-
if (this.isDestroyed) return !0;
|
|
204
|
-
let s = this._destroyers.length;
|
|
205
|
-
for (; --s >= 0; )
|
|
206
|
-
try {
|
|
207
|
-
await this._destroyers[s]();
|
|
208
|
-
} catch {
|
|
209
|
-
}
|
|
210
|
-
this._destroyers.length = 0, await this.destroyThis(), r(this);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function r(n) {
|
|
214
|
-
for (var d in n)
|
|
215
|
-
!(d in e.prototype) && typeof n[d] == "function" && (n[d] = y);
|
|
216
|
-
return n._isDestroyed = !0, !0;
|
|
217
|
-
}
|
|
218
|
-
return e;
|
|
219
|
-
}
|
|
220
|
-
const T = c(f), m = c(p);
|
|
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);
|
|
221
6
|
export {
|
|
222
|
-
|
|
7
|
+
l as Destroyable,
|
|
223
8
|
m as NodeDestroyable,
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
9
|
+
b as WebDestroyable,
|
|
10
|
+
e as createDestroyableSubClass,
|
|
11
|
+
c as destroyDestroyable,
|
|
12
|
+
d as destroyObject,
|
|
13
|
+
n as throwOnDestroyed
|
|
229
14
|
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gby/destroyable",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "@gby/destroyable 提供了用于构建可销毁对象的类的基类,用于使得地管理可销毁对象的生命周期",
|
|
5
|
-
"main": "./dist/index.
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
|
-
"
|
|
9
|
+
"node": {
|
|
10
|
+
"require": "./dist/index-node.cjs",
|
|
11
|
+
"types": "./dist/index-node.d.ts",
|
|
12
|
+
"import": "./dist/index-node.js"
|
|
13
|
+
},
|
|
14
|
+
"browser": {
|
|
15
|
+
"require": "./dist/index-web.cjs",
|
|
16
|
+
"types": "./dist/index-web.d.ts",
|
|
17
|
+
"import": "./dist/index-web.js"
|
|
18
|
+
},
|
|
19
|
+
"require": "./dist/index.cjs",
|
|
10
20
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js"
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"default": "./dist/index.js"
|
|
12
23
|
},
|
|
13
24
|
"type": "module",
|
|
14
25
|
"sideEffects": false,
|
package/dist/index.umd.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(t,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@gby/event-bus"),require("node:events")):typeof define=="function"&&define.amd?define(["exports","@gby/event-bus","node:events"],r):(t=typeof globalThis<"u"?globalThis:t||self,r(t.Destroyable={},t.eventBus,t.node_events))})(this,function(t,r,y){"use strict";var g=Object.defineProperty;var v=(t,r,y)=>r in t?g(t,r,{enumerable:!0,configurable:!0,writable:!0,value:y}):t[r]=y;var u=(t,r,y)=>v(t,typeof r!="symbol"?r+"":r,y);class a{constructor(){u(this,"_isDestroyed",!1);u(this,"_destroyers",[])}get isDestroyed(){return this._isDestroyed}disposeFun(e){return this._destroyers.push(e),e}cancelDisposeFun(e){const i=this._destroyers.indexOf(e);return this._destroyers.splice(i,1),e}disposeObj(e,i){const d=i?function(){return e.destroy()}:function(){return e.destroyAsync()};return this.disposeFun(d),e.__destroyable_destroyer=d,e}cancelDisposeObj(e){const i=e.__destroyable_destroyer;return i&&this.cancelDisposeFun(i),e}dispose(e,i){return typeof e=="function"?this.disposeFun(e):this.disposeObj(e,i)}cancelDispose(e){return typeof e=="function"?this.cancelDisposeFun(e):this.cancelDisposeObj(e)}destroyThis(){}destroy(){if(this.isDestroyed)return!0;let e=this._destroyers.length;for(;--e>=0;)try{this._destroyers[e]()}catch{}this._destroyers.length=0,this.destroyThis(),f(this)}async destroyAsync(){if(this.isDestroyed)return!0;let e=this._destroyers.length;for(;--e>=0;)try{await this._destroyers[e]()}catch{}this._destroyers.length=0,await this.destroyThis(),f(this)}}function h(){throw"已销毁"}function D(n){for(var e in n)typeof n[e]=="function"&&(n[e]=h);return n._isDestroyed=!0,!0}function f(n){for(var e in n)!(e in a.prototype)&&typeof n[e]=="function"&&(n[e]=h);return n._isDestroyed=!0,!0}function l(n){class e extends n{constructor(){super(...arguments);u(this,"_isDestroyed",!1);u(this,"_destroyers",[])}get isDestroyed(){return this._isDestroyed}disposeFun(s){return this._destroyers.push(s),s}cancelDisposeFun(s){const o=this._destroyers.indexOf(s);return this._destroyers.splice(o,1),s}disposeObj(s,o){const p=o?function(){return s.destroy()}:function(){return s.destroyAsync()};return this.disposeFun(p),s.__destroyable_destroyer=p,s}cancelDisposeObj(s){const o=s.__destroyable_destroyer;return o&&this.cancelDisposeFun(o),s}dispose(s,o){return typeof s=="function"?this.disposeFun(s):this.disposeObj(s,o)}cancelDispose(s){return typeof s=="function"?this.cancelDisposeFun(s):this.cancelDisposeObj(s)}destroyThis(){}destroy(){if(this.isDestroyed)return!0;let s=this._destroyers.length;for(;--s>=0;)try{this._destroyers[s]()}catch{}this._destroyers.length=0,this.destroyThis(),i(this)}async destroyAsync(){if(this.isDestroyed)return!0;let s=this._destroyers.length;for(;--s>=0;)try{await this._destroyers[s]()}catch{}this._destroyers.length=0,await this.destroyThis(),i(this)}}function i(d){for(var c in d)!(c in e.prototype)&&typeof d[c]=="function"&&(d[c]=h);return d._isDestroyed=!0,!0}return e}const _=l(r.EventBus),b=l(y.EventEmitter);t.Destroyable=a,t.NodeDestroyable=b,t.WebDestroyable=_,t.createDestroyableSubClass=l,t.destroyDestroyable=f,t.destroyObject=D,t.throwOnDestroyed=h,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
|
package/dist/tsdoc-metadata.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
-
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
-
{
|
|
4
|
-
"tsdocVersion": "0.12",
|
|
5
|
-
"toolPackages": [
|
|
6
|
-
{
|
|
7
|
-
"packageName": "@microsoft/api-extractor",
|
|
8
|
-
"packageVersion": "7.52.8"
|
|
9
|
-
}
|
|
10
|
-
]
|
|
11
|
-
}
|