@whitesev/utils 1.1.0 → 1.1.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/dist/index.amd.js +38 -41
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +38 -41
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +38 -41
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +38 -41
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +38 -41
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +38 -41
- package/dist/index.umd.js.map +1 -1
- package/dist/src/LockFunction.d.ts +4 -16
- package/package.json +1 -1
- package/src/LockFunction.ts +36 -31
- package/src/Utils.ts +11 -19
package/dist/index.cjs.js
CHANGED
|
@@ -2473,7 +2473,12 @@ class LockFunction {
|
|
|
2473
2473
|
#delayTime = 0;
|
|
2474
2474
|
#callback;
|
|
2475
2475
|
#context;
|
|
2476
|
+
lock;
|
|
2477
|
+
unlock;
|
|
2478
|
+
run;
|
|
2479
|
+
isLock;
|
|
2476
2480
|
constructor(callback, context, delayTime) {
|
|
2481
|
+
let that = this;
|
|
2477
2482
|
this.#callback = callback;
|
|
2478
2483
|
if (typeof context === "number") {
|
|
2479
2484
|
this.#delayTime = context;
|
|
@@ -2483,37 +2488,37 @@ class LockFunction {
|
|
|
2483
2488
|
this.#delayTime = delayTime;
|
|
2484
2489
|
this.#context = context;
|
|
2485
2490
|
}
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
}
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2491
|
+
/**
|
|
2492
|
+
* 锁
|
|
2493
|
+
*/
|
|
2494
|
+
this.lock = function () {
|
|
2495
|
+
that.#flag = true;
|
|
2496
|
+
};
|
|
2497
|
+
/**
|
|
2498
|
+
* 解锁
|
|
2499
|
+
*/
|
|
2500
|
+
this.unlock = function () {
|
|
2501
|
+
setTimeout(() => {
|
|
2502
|
+
that.#flag = false;
|
|
2503
|
+
}, that.#delayTime);
|
|
2504
|
+
};
|
|
2505
|
+
/**
|
|
2506
|
+
* 判断是否被锁
|
|
2507
|
+
*/
|
|
2508
|
+
this.isLock = function () {
|
|
2509
|
+
return that.#flag;
|
|
2510
|
+
};
|
|
2511
|
+
/**
|
|
2512
|
+
* 执行
|
|
2513
|
+
*/
|
|
2514
|
+
this.run = async function (...args) {
|
|
2515
|
+
if (that.isLock()) {
|
|
2516
|
+
return;
|
|
2517
|
+
}
|
|
2518
|
+
that.lock();
|
|
2519
|
+
await that.#callback.apply(that.#context, args);
|
|
2520
|
+
that.unlock();
|
|
2521
|
+
};
|
|
2517
2522
|
}
|
|
2518
2523
|
}
|
|
2519
2524
|
|
|
@@ -4646,42 +4651,35 @@ class Utils {
|
|
|
4646
4651
|
callback: () => { },
|
|
4647
4652
|
config: {
|
|
4648
4653
|
/**
|
|
4649
|
-
* @type {boolean|undefined}
|
|
4650
4654
|
* + true 监听以 target 为根节点的整个子树。包括子树中所有节点的属性,而不仅仅是针对 target
|
|
4651
4655
|
* + false (默认) 不生效
|
|
4652
4656
|
*/
|
|
4653
4657
|
subtree: void 0,
|
|
4654
4658
|
/**
|
|
4655
|
-
* @type {boolean|undefined}
|
|
4656
4659
|
* + true 监听 target 节点中发生的节点的新增与删除(同时,如果 subtree 为 true,会针对整个子树生效)
|
|
4657
4660
|
* + false (默认) 不生效
|
|
4658
4661
|
*/
|
|
4659
4662
|
childList: void 0,
|
|
4660
4663
|
/**
|
|
4661
|
-
* @type {boolean|undefined}
|
|
4662
4664
|
* + true 观察所有监听的节点属性值的变化。默认值为 true,当声明了 attributeFilter 或 attributeOldValue
|
|
4663
4665
|
* + false (默认) 不生效
|
|
4664
4666
|
*/
|
|
4665
4667
|
attributes: void 0,
|
|
4666
4668
|
/**
|
|
4667
4669
|
* 一个用于声明哪些属性名会被监听的数组。如果不声明该属性,所有属性的变化都将触发通知
|
|
4668
|
-
* @type {[...string]|undefined}
|
|
4669
4670
|
*/
|
|
4670
4671
|
attributeFilter: void 0,
|
|
4671
4672
|
/**
|
|
4672
|
-
* @type {boolean|undefined}
|
|
4673
4673
|
* + true 记录上一次被监听的节点的属性变化;可查阅 MutationObserver 中的 Monitoring attribute values 了解关于观察属性变化和属性值记录的详情
|
|
4674
4674
|
* + false (默认) 不生效
|
|
4675
4675
|
*/
|
|
4676
4676
|
attributeOldValue: void 0,
|
|
4677
4677
|
/**
|
|
4678
|
-
* @type {boolean|undefined}
|
|
4679
4678
|
* + true 监听声明的 target 节点上所有字符的变化。默认值为 true,如果声明了 characterDataOldValue
|
|
4680
4679
|
* + false (默认) 不生效
|
|
4681
4680
|
*/
|
|
4682
4681
|
characterData: void 0,
|
|
4683
4682
|
/**
|
|
4684
|
-
* @type {boolean|undefined}
|
|
4685
4683
|
* + true 记录前一个被监听的节点中发生的文本变化
|
|
4686
4684
|
* + false (默认) 不生效
|
|
4687
4685
|
*/
|
|
@@ -4689,11 +4687,10 @@ class Utils {
|
|
|
4689
4687
|
},
|
|
4690
4688
|
};
|
|
4691
4689
|
observer_config = UtilsContext.assign(default_obverser_config, observer_config);
|
|
4692
|
-
let
|
|
4690
|
+
let windowMutationObserver = window.MutationObserver ||
|
|
4693
4691
|
UtilsCore.window.webkitMutationObserver ||
|
|
4694
4692
|
UtilsCore.window.MozMutationObserver;
|
|
4695
|
-
|
|
4696
|
-
let mutationObserver = new MutationObserver(function (mutations, observer) {
|
|
4693
|
+
let mutationObserver = new windowMutationObserver(function (mutations, observer) {
|
|
4697
4694
|
observer_config?.callback(mutations, observer);
|
|
4698
4695
|
});
|
|
4699
4696
|
if (target instanceof Node) {
|