@gby/destroyable 3.6.2 → 3.7.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/DestroyableEventEmitter.d.ts +0 -1
- package/dist/DestroyableEventEmitter.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +381 -15
- package/package.json +1 -6
- package/dist/DestroyableEventTarget-CIMBV0bD.js +0 -377
- package/dist/DestroyableEventTarget-uZtYhcb1.cjs +0 -1
- package/dist/index-web.cjs +0 -1
- package/dist/index-web.js +0 -9
- package/doc/api/destroyable.createdestroyablesubclass.md +0 -82
- package/doc/api/destroyable.destroyable._destroyers.md +0 -13
- package/doc/api/destroyable.destroyable._isdestroyed.md +0 -11
- package/doc/api/destroyable.destroyable.canceldispose.md +0 -49
- package/doc/api/destroyable.destroyable.canceldispose_1.md +0 -49
- package/doc/api/destroyable.destroyable.canceldispose_2.md +0 -49
- package/doc/api/destroyable.destroyable.canceldisposefun.md +0 -52
- package/doc/api/destroyable.destroyable.canceldisposeobj.md +0 -52
- package/doc/api/destroyable.destroyable.destroy.md +0 -17
- package/doc/api/destroyable.destroyable.destroyasync.md +0 -21
- package/doc/api/destroyable.destroyable.destroythis.md +0 -21
- package/doc/api/destroyable.destroyable.dispose.md +0 -51
- package/doc/api/destroyable.destroyable.dispose_1.md +0 -65
- package/doc/api/destroyable.destroyable.dispose_2.md +0 -65
- package/doc/api/destroyable.destroyable.disposefun.md +0 -53
- package/doc/api/destroyable.destroyable.disposeobj.md +0 -68
- package/doc/api/destroyable.destroyable.isdestroyed.md +0 -13
- package/doc/api/destroyable.destroyable.md +0 -287
- package/doc/api/destroyable.destroyablesub.md +0 -15
- package/doc/api/destroyable.destroyablesubclass.md +0 -13
- package/doc/api/destroyable.destroydestroyable.md +0 -52
- package/doc/api/destroyable.destroyobject.md +0 -52
- package/doc/api/destroyable.fundestroyer.md +0 -13
- package/doc/api/destroyable.md +0 -225
- package/doc/api/destroyable.nodedestroyable.md +0 -39
- package/doc/api/destroyable.nodedestroyableclass.md +0 -15
- package/doc/api/destroyable.throwondestroyed.md +0 -17
- package/doc/api/destroyable.webdestroyable.md +0 -39
- package/doc/api/destroyable.webdestroyableclass.md +0 -15
- package/doc/api/index.md +0 -31
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
import { serialCallAllFuns as h } from "com-tools";
|
|
2
|
-
import { EventBus as u } from "@gby/event-bus";
|
|
3
|
-
class c {
|
|
4
|
-
/**
|
|
5
|
-
* 引用计数
|
|
6
|
-
* @remarks
|
|
7
|
-
* 引用计数为 0 时,对象才会被销毁
|
|
8
|
-
*/
|
|
9
|
-
refCount = 0;
|
|
10
|
-
/**
|
|
11
|
-
* 是否已经销毁
|
|
12
|
-
*/
|
|
13
|
-
get isDestroyed() {
|
|
14
|
-
return this._isDestroyed;
|
|
15
|
-
}
|
|
16
|
-
_isDestroyed = !1;
|
|
17
|
-
/**
|
|
18
|
-
* 是否可以销毁
|
|
19
|
-
*/
|
|
20
|
-
get canDestroy() {
|
|
21
|
-
return !this.isDestroyed && this.refCount <= 0;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* 销毁者
|
|
25
|
-
*/
|
|
26
|
-
_destroyers = [];
|
|
27
|
-
/**
|
|
28
|
-
* 添加销毁者
|
|
29
|
-
* @param fun
|
|
30
|
-
* @returns 返回销毁者的顺序
|
|
31
|
-
*/
|
|
32
|
-
disposeFun(e) {
|
|
33
|
-
return this._destroyers.push(e), e;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* 取消销毁者函数
|
|
37
|
-
* @param fun
|
|
38
|
-
* @returns
|
|
39
|
-
*/
|
|
40
|
-
cancelDisposeFun(e) {
|
|
41
|
-
const t = this._destroyers.indexOf(e);
|
|
42
|
-
return this._destroyers.splice(t, 1), e;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* 添加销毁对象
|
|
46
|
-
* @param obj
|
|
47
|
-
* @param sync - 表示是否使用 `obj.destroySync()` 方法进行销毁;默认使用 `obj.destroy()` 方法进行销毁
|
|
48
|
-
* @returns
|
|
49
|
-
*/
|
|
50
|
-
disposeObj(e, t) {
|
|
51
|
-
const s = t ? function() {
|
|
52
|
-
return e.destroySync();
|
|
53
|
-
} : function() {
|
|
54
|
-
return e.destroy();
|
|
55
|
-
};
|
|
56
|
-
return this.disposeFun(s), e.__destroyable_destroyer = s, e;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* 取消销毁者函数
|
|
60
|
-
* @param fun
|
|
61
|
-
* @returns
|
|
62
|
-
*/
|
|
63
|
-
cancelDisposeObj(e) {
|
|
64
|
-
const t = e.__destroyable_destroyer;
|
|
65
|
-
return t && this.cancelDisposeFun(t), e;
|
|
66
|
-
}
|
|
67
|
-
dispose(e, t) {
|
|
68
|
-
return typeof e == "function" ? this.disposeFun(e) : this.disposeObj(e, t);
|
|
69
|
-
}
|
|
70
|
-
cancelDispose(e) {
|
|
71
|
-
return typeof e == "function" ? this.cancelDisposeFun(e) : this.cancelDisposeObj(e);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* 自己的销毁方法
|
|
75
|
-
* @remarks
|
|
76
|
-
* 子类根据需要进行重载
|
|
77
|
-
*/
|
|
78
|
-
destroyThis() {
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* 同步销毁
|
|
82
|
-
* @remarks
|
|
83
|
-
* 会逆序依次同步调用所有销毁函数,并不会等待上一个销毁函数异步执行完成
|
|
84
|
-
*/
|
|
85
|
-
destroySync() {
|
|
86
|
-
if (!this.canDestroy) return this.isDestroyed;
|
|
87
|
-
let e = this._destroyers.length;
|
|
88
|
-
for (; --e >= 0; ) {
|
|
89
|
-
const t = this._destroyers[e];
|
|
90
|
-
try {
|
|
91
|
-
t();
|
|
92
|
-
} catch (s) {
|
|
93
|
-
console.error("销毁函数在同步销毁时出错", this, t, s);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
this._destroyers.length = 0;
|
|
97
|
-
try {
|
|
98
|
-
this.destroyThis();
|
|
99
|
-
} catch (t) {
|
|
100
|
-
console.error("destroyThis 在异步销毁时出错", this, t);
|
|
101
|
-
}
|
|
102
|
-
return o(this), !0;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* 串行销毁
|
|
106
|
-
* @remarks
|
|
107
|
-
* 会逆序依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
|
|
108
|
-
* @returns 如果所有的销毁函数都是同步的,那么返回 true;如果有任何一个销毁函数是异步的,那么返回一个 Promise 对象
|
|
109
|
-
*/
|
|
110
|
-
destroy() {
|
|
111
|
-
if (!this.canDestroy) return this.isDestroyed;
|
|
112
|
-
const e = this._destroyers.toReversed();
|
|
113
|
-
e.push(this.destroyThis), this._destroyers.length = 0;
|
|
114
|
-
const t = h(e, this, null, (s, r) => {
|
|
115
|
-
console.error("销毁函数在串行销毁时出错", this, r, s);
|
|
116
|
-
});
|
|
117
|
-
return t instanceof Promise ? t.then(() => (o(this), !0)) : (o(this), !0);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function d() {
|
|
121
|
-
throw "已销毁";
|
|
122
|
-
}
|
|
123
|
-
function f(i) {
|
|
124
|
-
for (var e in i)
|
|
125
|
-
typeof i[e] == "function" && (i[e] = d);
|
|
126
|
-
return i._isDestroyed = !0, !0;
|
|
127
|
-
}
|
|
128
|
-
function o(i) {
|
|
129
|
-
for (var e in i)
|
|
130
|
-
!(e in c.prototype) && typeof i[e] == "function" && (i[e] = d);
|
|
131
|
-
return i._isDestroyed = !0, !0;
|
|
132
|
-
}
|
|
133
|
-
function p(i) {
|
|
134
|
-
class e extends i {
|
|
135
|
-
/**
|
|
136
|
-
* 引用计数
|
|
137
|
-
* @remarks
|
|
138
|
-
* 引用计数为 0 时,对象才会被销毁
|
|
139
|
-
*/
|
|
140
|
-
refCount = 0;
|
|
141
|
-
/**
|
|
142
|
-
* 是否已经销毁
|
|
143
|
-
*/
|
|
144
|
-
get isDestroyed() {
|
|
145
|
-
return this._isDestroyed;
|
|
146
|
-
}
|
|
147
|
-
_isDestroyed = !1;
|
|
148
|
-
/**
|
|
149
|
-
* 是否可以销毁
|
|
150
|
-
*/
|
|
151
|
-
get canDestroy() {
|
|
152
|
-
return !this.isDestroyed && this.refCount <= 0;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* 销毁者
|
|
156
|
-
*/
|
|
157
|
-
_destroyers = [];
|
|
158
|
-
/**
|
|
159
|
-
* 添加销毁者
|
|
160
|
-
* @param fun
|
|
161
|
-
* @returns 返回销毁者的顺序
|
|
162
|
-
*/
|
|
163
|
-
disposeFun(s) {
|
|
164
|
-
return this._destroyers.push(s), s;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* 取消销毁者函数
|
|
168
|
-
* @param fun
|
|
169
|
-
* @returns
|
|
170
|
-
*/
|
|
171
|
-
cancelDisposeFun(s) {
|
|
172
|
-
const r = this._destroyers.indexOf(s);
|
|
173
|
-
return this._destroyers.splice(r, 1), s;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* 添加销毁对象
|
|
177
|
-
* @param obj
|
|
178
|
-
* @param sync - 表示是否使用 `obj.destroySync()` 方法进行销毁;默认使用 `obj.destroy()` 方法进行销毁
|
|
179
|
-
* @returns
|
|
180
|
-
*/
|
|
181
|
-
disposeObj(s, r) {
|
|
182
|
-
const n = r ? function() {
|
|
183
|
-
return s.destroySync();
|
|
184
|
-
} : function() {
|
|
185
|
-
return s.destroy();
|
|
186
|
-
};
|
|
187
|
-
return this.disposeFun(n), s.__destroyable_destroyer = n, s;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* 取消销毁者函数
|
|
191
|
-
* @param fun
|
|
192
|
-
* @returns
|
|
193
|
-
*/
|
|
194
|
-
cancelDisposeObj(s) {
|
|
195
|
-
const r = s.__destroyable_destroyer;
|
|
196
|
-
return r && this.cancelDisposeFun(r), s;
|
|
197
|
-
}
|
|
198
|
-
dispose(s, r) {
|
|
199
|
-
return typeof s == "function" ? this.disposeFun(s) : this.disposeObj(s, r);
|
|
200
|
-
}
|
|
201
|
-
cancelDispose(s) {
|
|
202
|
-
return typeof s == "function" ? this.cancelDisposeFun(s) : this.cancelDisposeObj(s);
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* 自己的销毁方法
|
|
206
|
-
* @remarks
|
|
207
|
-
* 子类根据需要进行重载
|
|
208
|
-
*/
|
|
209
|
-
destroyThis() {
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* 同步销毁
|
|
213
|
-
* @remarks
|
|
214
|
-
* 会逆序依次同步调用所有销毁函数,并不会等待上一个销毁函数异步执行完成
|
|
215
|
-
*/
|
|
216
|
-
destroySync() {
|
|
217
|
-
if (!this.canDestroy) return this.isDestroyed;
|
|
218
|
-
let s = this._destroyers.length;
|
|
219
|
-
for (; --s >= 0; ) {
|
|
220
|
-
const r = this._destroyers[s];
|
|
221
|
-
try {
|
|
222
|
-
r();
|
|
223
|
-
} catch (n) {
|
|
224
|
-
console.error("销毁函数在同步销毁时出错", this, r, n);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
this._destroyers.length = 0;
|
|
228
|
-
try {
|
|
229
|
-
this.destroyThis();
|
|
230
|
-
} catch (r) {
|
|
231
|
-
console.error("destroyThis 在异步销毁时出错", this, r);
|
|
232
|
-
}
|
|
233
|
-
return o(this), !0;
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* 串行销毁
|
|
237
|
-
* @remarks
|
|
238
|
-
* 会逆序依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
|
|
239
|
-
* @returns 如果所有的销毁函数都是同步的,那么返回 true;如果有任何一个销毁函数是异步的,那么返回一个 Promise 对象
|
|
240
|
-
*/
|
|
241
|
-
destroy() {
|
|
242
|
-
if (!this.canDestroy) return this.isDestroyed;
|
|
243
|
-
const s = this._destroyers.toReversed();
|
|
244
|
-
s.push(this.destroyThis), this._destroyers.length = 0;
|
|
245
|
-
const r = h(s, this, null, (n, y) => {
|
|
246
|
-
console.error("销毁函数在串行销毁时出错", this, y, n);
|
|
247
|
-
});
|
|
248
|
-
return r instanceof Promise ? r.then(() => (o(this), !0)) : (o(this), !0);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return e;
|
|
252
|
-
}
|
|
253
|
-
class D extends u {
|
|
254
|
-
/**
|
|
255
|
-
* 引用计数
|
|
256
|
-
* @remarks
|
|
257
|
-
* 引用计数为 0 时,对象才会被销毁
|
|
258
|
-
*/
|
|
259
|
-
refCount = 0;
|
|
260
|
-
/**
|
|
261
|
-
* 是否已经销毁
|
|
262
|
-
*/
|
|
263
|
-
get isDestroyed() {
|
|
264
|
-
return this._isDestroyed;
|
|
265
|
-
}
|
|
266
|
-
_isDestroyed = !1;
|
|
267
|
-
/**
|
|
268
|
-
* 是否可以销毁
|
|
269
|
-
*/
|
|
270
|
-
get canDestroy() {
|
|
271
|
-
return !this.isDestroyed && this.refCount <= 0;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* 销毁者
|
|
275
|
-
*/
|
|
276
|
-
_destroyers = [];
|
|
277
|
-
/**
|
|
278
|
-
* 添加销毁者
|
|
279
|
-
* @param fun
|
|
280
|
-
* @returns 返回销毁者的顺序
|
|
281
|
-
*/
|
|
282
|
-
disposeFun(e) {
|
|
283
|
-
return this._destroyers.push(e), e;
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* 取消销毁者函数
|
|
287
|
-
* @param fun
|
|
288
|
-
* @returns
|
|
289
|
-
*/
|
|
290
|
-
cancelDisposeFun(e) {
|
|
291
|
-
const t = this._destroyers.indexOf(e);
|
|
292
|
-
return this._destroyers.splice(t, 1), e;
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* 添加销毁对象
|
|
296
|
-
* @param obj
|
|
297
|
-
* @param sync - 表示是否使用 `obj.destroySync()` 方法进行销毁;默认使用 `obj.destroy()` 方法进行销毁
|
|
298
|
-
* @returns
|
|
299
|
-
*/
|
|
300
|
-
disposeObj(e, t) {
|
|
301
|
-
const s = t ? function() {
|
|
302
|
-
return e.destroySync();
|
|
303
|
-
} : function() {
|
|
304
|
-
return e.destroy();
|
|
305
|
-
};
|
|
306
|
-
return this.disposeFun(s), e.__destroyable_destroyer = s, e;
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* 取消销毁者函数
|
|
310
|
-
* @param fun
|
|
311
|
-
* @returns
|
|
312
|
-
*/
|
|
313
|
-
cancelDisposeObj(e) {
|
|
314
|
-
const t = e.__destroyable_destroyer;
|
|
315
|
-
return t && this.cancelDisposeFun(t), e;
|
|
316
|
-
}
|
|
317
|
-
dispose(e, t) {
|
|
318
|
-
return typeof e == "function" ? this.disposeFun(e) : this.disposeObj(e, t);
|
|
319
|
-
}
|
|
320
|
-
cancelDispose(e) {
|
|
321
|
-
return typeof e == "function" ? this.cancelDisposeFun(e) : this.cancelDisposeObj(e);
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* 自己的销毁方法
|
|
325
|
-
* @remarks
|
|
326
|
-
* 子类根据需要进行重载
|
|
327
|
-
*/
|
|
328
|
-
destroyThis() {
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* 同步销毁
|
|
332
|
-
* @remarks
|
|
333
|
-
* 会逆序依次同步调用所有销毁函数,并不会等待上一个销毁函数异步执行完成
|
|
334
|
-
*/
|
|
335
|
-
destroySync() {
|
|
336
|
-
if (!this.canDestroy) return this.isDestroyed;
|
|
337
|
-
let e = this._destroyers.length;
|
|
338
|
-
for (; --e >= 0; ) {
|
|
339
|
-
const t = this._destroyers[e];
|
|
340
|
-
try {
|
|
341
|
-
t();
|
|
342
|
-
} catch (s) {
|
|
343
|
-
console.error("销毁函数在同步销毁时出错", this, t, s);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
this._destroyers.length = 0;
|
|
347
|
-
try {
|
|
348
|
-
this.destroyThis();
|
|
349
|
-
} catch (t) {
|
|
350
|
-
console.error("destroyThis 在异步销毁时出错", this, t);
|
|
351
|
-
}
|
|
352
|
-
return o(this), !0;
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* 串行销毁
|
|
356
|
-
* @remarks
|
|
357
|
-
* 会逆序依次执行销毁,并且只有上一个销毁完成之后才会执行下一个销毁
|
|
358
|
-
* @returns 如果所有的销毁函数都是同步的,那么返回 true;如果有任何一个销毁函数是异步的,那么返回一个 Promise 对象
|
|
359
|
-
*/
|
|
360
|
-
destroy() {
|
|
361
|
-
if (!this.canDestroy) return this.isDestroyed;
|
|
362
|
-
const e = this._destroyers.toReversed();
|
|
363
|
-
e.push(this.destroyThis), this._destroyers.length = 0;
|
|
364
|
-
const t = h(e, this, null, (s, r) => {
|
|
365
|
-
console.error("销毁函数在串行销毁时出错", this, r, s);
|
|
366
|
-
});
|
|
367
|
-
return t instanceof Promise ? t.then(() => (o(this), !0)) : (o(this), !0);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
export {
|
|
371
|
-
c as D,
|
|
372
|
-
D as a,
|
|
373
|
-
f as b,
|
|
374
|
-
p as c,
|
|
375
|
-
o as d,
|
|
376
|
-
d as t
|
|
377
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const h=require("com-tools"),c=require("@gby/event-bus");class d{refCount=0;get isDestroyed(){return this._isDestroyed}_isDestroyed=!1;get canDestroy(){return!this.isDestroyed&&this.refCount<=0}_destroyers=[];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.destroySync()}:function(){return e.destroy()};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(){}destroySync(){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(this),!0}destroy(){if(!this.canDestroy)return this.isDestroyed;const e=this._destroyers.toReversed();e.push(this.destroyThis),this._destroyers.length=0;const t=h.serialCallAllFuns(e,this,null,(s,r)=>{console.error("销毁函数在串行销毁时出错",this,r,s)});return t instanceof Promise?t.then(()=>(o(this),!0)):(o(this),!0)}}function y(){throw"已销毁"}function l(i){for(var e in i)typeof i[e]=="function"&&(i[e]=y);return i._isDestroyed=!0,!0}function o(i){for(var e in i)!(e in d.prototype)&&typeof i[e]=="function"&&(i[e]=y);return i._isDestroyed=!0,!0}function a(i){class e extends i{refCount=0;get isDestroyed(){return this._isDestroyed}_isDestroyed=!1;get canDestroy(){return!this.isDestroyed&&this.refCount<=0}_destroyers=[];disposeFun(s){return this._destroyers.push(s),s}cancelDisposeFun(s){const r=this._destroyers.indexOf(s);return this._destroyers.splice(r,1),s}disposeObj(s,r){const n=r?function(){return s.destroySync()}:function(){return s.destroy()};return this.disposeFun(n),s.__destroyable_destroyer=n,s}cancelDisposeObj(s){const r=s.__destroyable_destroyer;return r&&this.cancelDisposeFun(r),s}dispose(s,r){return typeof s=="function"?this.disposeFun(s):this.disposeObj(s,r)}cancelDispose(s){return typeof s=="function"?this.cancelDisposeFun(s):this.cancelDisposeObj(s)}destroyThis(){}destroySync(){if(!this.canDestroy)return this.isDestroyed;let s=this._destroyers.length;for(;--s>=0;){const r=this._destroyers[s];try{r()}catch(n){console.error("销毁函数在同步销毁时出错",this,r,n)}}this._destroyers.length=0;try{this.destroyThis()}catch(r){console.error("destroyThis 在异步销毁时出错",this,r)}return o(this),!0}destroy(){if(!this.canDestroy)return this.isDestroyed;const s=this._destroyers.toReversed();s.push(this.destroyThis),this._destroyers.length=0;const r=h.serialCallAllFuns(s,this,null,(n,u)=>{console.error("销毁函数在串行销毁时出错",this,u,n)});return r instanceof Promise?r.then(()=>(o(this),!0)):(o(this),!0)}}return e}class f extends c.EventBus{refCount=0;get isDestroyed(){return this._isDestroyed}_isDestroyed=!1;get canDestroy(){return!this.isDestroyed&&this.refCount<=0}_destroyers=[];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.destroySync()}:function(){return e.destroy()};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(){}destroySync(){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(this),!0}destroy(){if(!this.canDestroy)return this.isDestroyed;const e=this._destroyers.toReversed();e.push(this.destroyThis),this._destroyers.length=0;const t=h.serialCallAllFuns(e,this,null,(s,r)=>{console.error("销毁函数在串行销毁时出错",this,r,s)});return t instanceof Promise?t.then(()=>(o(this),!0)):(o(this),!0)}}exports.Destroyable=d;exports.DestroyableEventTarget=f;exports.createDestroyableSubClass=a;exports.destroyDestroyable=o;exports.destroyObject=l;exports.throwOnDestroyed=y;
|
package/dist/index-web.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./DestroyableEventTarget-uZtYhcb1.cjs");exports.Destroyable=e.Destroyable;exports.DestroyableEventTarget=e.DestroyableEventTarget;exports.createDestroyableSubClass=e.createDestroyableSubClass;exports.destroyDestroyable=e.destroyDestroyable;exports.destroyObject=e.destroyObject;exports.throwOnDestroyed=e.throwOnDestroyed;
|
package/dist/index-web.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { D as a, a as t, c as r, d as o, b, t as y } from "./DestroyableEventTarget-CIMBV0bD.js";
|
|
2
|
-
export {
|
|
3
|
-
a as Destroyable,
|
|
4
|
-
t as DestroyableEventTarget,
|
|
5
|
-
r as createDestroyableSubClass,
|
|
6
|
-
o as destroyDestroyable,
|
|
7
|
-
b as destroyObject,
|
|
8
|
-
y as throwOnDestroyed
|
|
9
|
-
};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
-
|
|
3
|
-
[Home](./index.md) > [@gby/destroyable](./destroyable.md) > [createDestroyableSubClass](./destroyable.createdestroyablesubclass.md)
|
|
4
|
-
|
|
5
|
-
## createDestroyableSubClass() function
|
|
6
|
-
|
|
7
|
-
创建可销毁的子类
|
|
8
|
-
|
|
9
|
-
**Signature:**
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
export declare function createDestroyableSubClass<P extends new (...args: any) => Object>(ParentClass: P): {
|
|
13
|
-
new (...args: any): {
|
|
14
|
-
readonly isDestroyed: boolean;
|
|
15
|
-
_isDestroyed: boolean;
|
|
16
|
-
_destroyers: FunDestroyer[];
|
|
17
|
-
disposeFun<T extends FunDestroyer>(fun: T): T;
|
|
18
|
-
cancelDisposeFun<T extends FunDestroyer>(fun: T): T;
|
|
19
|
-
disposeObj<T extends /*elided*/ any>(obj: T, sync?: boolean): T;
|
|
20
|
-
cancelDisposeObj<T extends /*elided*/ any>(obj: T): T;
|
|
21
|
-
dispose<T extends FunDestroyer>(fun: T): T;
|
|
22
|
-
dispose<T extends /*elided*/ any>(obj: T, asyncDestroy?: boolean): T;
|
|
23
|
-
dispose<T extends /*elided*/ any | FunDestroyer>(objOrFun: T, asyncDestroy?: boolean): T;
|
|
24
|
-
cancelDispose<T extends FunDestroyer>(fun: T): T;
|
|
25
|
-
cancelDispose<T extends /*elided*/ any>(obj: T): T;
|
|
26
|
-
cancelDispose<T extends /*elided*/ any | FunDestroyer>(objOrFun: T): T;
|
|
27
|
-
destroyThis(): void;
|
|
28
|
-
destroy(): true | undefined;
|
|
29
|
-
destroyAsync(): Promise<true | undefined>;
|
|
30
|
-
constructor: Function;
|
|
31
|
-
toString(): string;
|
|
32
|
-
toLocaleString(): string;
|
|
33
|
-
valueOf(): Object;
|
|
34
|
-
hasOwnProperty(v: PropertyKey): boolean;
|
|
35
|
-
isPrototypeOf(v: Object): boolean;
|
|
36
|
-
propertyIsEnumerable(v: PropertyKey): boolean;
|
|
37
|
-
};
|
|
38
|
-
} & P;
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Parameters
|
|
42
|
-
|
|
43
|
-
<table><thead><tr><th>
|
|
44
|
-
|
|
45
|
-
Parameter
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
</th><th>
|
|
49
|
-
|
|
50
|
-
Type
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
</th><th>
|
|
54
|
-
|
|
55
|
-
Description
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
</th></tr></thead>
|
|
59
|
-
<tbody><tr><td>
|
|
60
|
-
|
|
61
|
-
ParentClass
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
</td><td>
|
|
65
|
-
|
|
66
|
-
P
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
</td><td>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
</td></tr>
|
|
73
|
-
</tbody></table>
|
|
74
|
-
**Returns:**
|
|
75
|
-
|
|
76
|
-
{ new (...args: any): { readonly isDestroyed: boolean; \_isDestroyed: boolean; \_destroyers: [FunDestroyer](./destroyable.fundestroyer.md)<!-- -->\[\]; disposeFun<T extends [FunDestroyer](./destroyable.fundestroyer.md)<!-- -->>(fun: T): T; cancelDisposeFun<T extends [FunDestroyer](./destroyable.fundestroyer.md)<!-- -->>(fun: T): T; disposeObj<T extends /\*elided\*/ any>(obj: T, sync?: boolean): T; cancelDisposeObj<T extends /\*elided\*/ any>(obj: T): T; dispose<T extends [FunDestroyer](./destroyable.fundestroyer.md)<!-- -->>(fun: T): T; dispose<T extends /\*elided\*/ any>(obj: T, asyncDestroy?: boolean): T; dispose<T extends /\*elided\*/ any \| [FunDestroyer](./destroyable.fundestroyer.md)<!-- -->>(objOrFun: T, asyncDestroy?: boolean): T; cancelDispose<T extends [FunDestroyer](./destroyable.fundestroyer.md)<!-- -->>(fun: T): T; cancelDispose<T extends /\*elided\*/ any>(obj: T): T; cancelDispose<T extends /\*elided\*/ any \| [FunDestroyer](./destroyable.fundestroyer.md)<!-- -->>(objOrFun: T): T; destroyThis(): void; destroy(): true \| undefined; destroyAsync(): Promise<true \| undefined>; constructor: Function; toString(): string; toLocaleString(): string; valueOf(): Object; hasOwnProperty(v: PropertyKey): boolean; isPrototypeOf(v: Object): boolean; propertyIsEnumerable(v: PropertyKey): boolean; }; } & P
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
## Remarks
|
|
80
|
-
|
|
81
|
-
用于根据传入的父类 动态生成可可销毁的子类
|
|
82
|
-
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
-
|
|
3
|
-
[Home](./index.md) > [@gby/destroyable](./destroyable.md) > [Destroyable](./destroyable.destroyable.md) > [\_destroyers](./destroyable.destroyable._destroyers.md)
|
|
4
|
-
|
|
5
|
-
## Destroyable.\_destroyers property
|
|
6
|
-
|
|
7
|
-
销毁者
|
|
8
|
-
|
|
9
|
-
**Signature:**
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
_destroyers: FunDestroyer[];
|
|
13
|
-
```
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
-
|
|
3
|
-
[Home](./index.md) > [@gby/destroyable](./destroyable.md) > [Destroyable](./destroyable.destroyable.md) > [\_isDestroyed](./destroyable.destroyable._isdestroyed.md)
|
|
4
|
-
|
|
5
|
-
## Destroyable.\_isDestroyed property
|
|
6
|
-
|
|
7
|
-
**Signature:**
|
|
8
|
-
|
|
9
|
-
```typescript
|
|
10
|
-
_isDestroyed: boolean;
|
|
11
|
-
```
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
-
|
|
3
|
-
[Home](./index.md) > [@gby/destroyable](./destroyable.md) > [Destroyable](./destroyable.destroyable.md) > [cancelDispose](./destroyable.destroyable.canceldispose.md)
|
|
4
|
-
|
|
5
|
-
## Destroyable.cancelDispose() method
|
|
6
|
-
|
|
7
|
-
**Signature:**
|
|
8
|
-
|
|
9
|
-
```typescript
|
|
10
|
-
cancelDispose<T extends FunDestroyer>(fun: T): T;
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Parameters
|
|
14
|
-
|
|
15
|
-
<table><thead><tr><th>
|
|
16
|
-
|
|
17
|
-
Parameter
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
</th><th>
|
|
21
|
-
|
|
22
|
-
Type
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
</th><th>
|
|
26
|
-
|
|
27
|
-
Description
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
</th></tr></thead>
|
|
31
|
-
<tbody><tr><td>
|
|
32
|
-
|
|
33
|
-
fun
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
</td><td>
|
|
37
|
-
|
|
38
|
-
T
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
</td><td>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
</td></tr>
|
|
45
|
-
</tbody></table>
|
|
46
|
-
**Returns:**
|
|
47
|
-
|
|
48
|
-
T
|
|
49
|
-
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
-
|
|
3
|
-
[Home](./index.md) > [@gby/destroyable](./destroyable.md) > [Destroyable](./destroyable.destroyable.md) > [cancelDispose](./destroyable.destroyable.canceldispose_1.md)
|
|
4
|
-
|
|
5
|
-
## Destroyable.cancelDispose() method
|
|
6
|
-
|
|
7
|
-
**Signature:**
|
|
8
|
-
|
|
9
|
-
```typescript
|
|
10
|
-
cancelDispose<T extends Destroyable>(obj: T): T;
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Parameters
|
|
14
|
-
|
|
15
|
-
<table><thead><tr><th>
|
|
16
|
-
|
|
17
|
-
Parameter
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
</th><th>
|
|
21
|
-
|
|
22
|
-
Type
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
</th><th>
|
|
26
|
-
|
|
27
|
-
Description
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
</th></tr></thead>
|
|
31
|
-
<tbody><tr><td>
|
|
32
|
-
|
|
33
|
-
obj
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
</td><td>
|
|
37
|
-
|
|
38
|
-
T
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
</td><td>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
</td></tr>
|
|
45
|
-
</tbody></table>
|
|
46
|
-
**Returns:**
|
|
47
|
-
|
|
48
|
-
T
|
|
49
|
-
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
2
|
-
|
|
3
|
-
[Home](./index.md) > [@gby/destroyable](./destroyable.md) > [Destroyable](./destroyable.destroyable.md) > [cancelDispose](./destroyable.destroyable.canceldispose_2.md)
|
|
4
|
-
|
|
5
|
-
## Destroyable.cancelDispose() method
|
|
6
|
-
|
|
7
|
-
**Signature:**
|
|
8
|
-
|
|
9
|
-
```typescript
|
|
10
|
-
cancelDispose<T extends Destroyable | FunDestroyer>(objOrFun: T): T;
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Parameters
|
|
14
|
-
|
|
15
|
-
<table><thead><tr><th>
|
|
16
|
-
|
|
17
|
-
Parameter
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
</th><th>
|
|
21
|
-
|
|
22
|
-
Type
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
</th><th>
|
|
26
|
-
|
|
27
|
-
Description
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
</th></tr></thead>
|
|
31
|
-
<tbody><tr><td>
|
|
32
|
-
|
|
33
|
-
objOrFun
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
</td><td>
|
|
37
|
-
|
|
38
|
-
T
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
</td><td>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
</td></tr>
|
|
45
|
-
</tbody></table>
|
|
46
|
-
**Returns:**
|
|
47
|
-
|
|
48
|
-
T
|
|
49
|
-
|