@whitesev/utils 2.10.0 → 2.11.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/index.amd.js +89 -22
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +89 -22
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +89 -22
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +89 -22
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +89 -22
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +89 -22
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Utils.d.ts +30 -5
- package/dist/types/src/Vue.d.ts +24 -1
- package/package.json +1 -1
- package/src/Utils.ts +30 -5
- package/src/Vue.ts +92 -21
package/dist/index.esm.js
CHANGED
|
@@ -237,7 +237,7 @@ const clearTimeout$1 = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
|
|
|
237
237
|
const setInterval$1 = (...args) => loadOrReturnBroker().setInterval(...args);
|
|
238
238
|
const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
|
|
239
239
|
|
|
240
|
-
const version = "2.
|
|
240
|
+
const version = "2.11.0";
|
|
241
241
|
|
|
242
242
|
/* eslint-disable */
|
|
243
243
|
// ==UserScript==
|
|
@@ -5334,7 +5334,6 @@ class GMMenu {
|
|
|
5334
5334
|
}
|
|
5335
5335
|
}
|
|
5336
5336
|
|
|
5337
|
-
// @ts-nocheck
|
|
5338
5337
|
const VueUtils = {
|
|
5339
5338
|
/** 标签 */
|
|
5340
5339
|
ReactiveFlags: {
|
|
@@ -5374,9 +5373,11 @@ class ReactiveEffect {
|
|
|
5374
5373
|
active = true;
|
|
5375
5374
|
fn;
|
|
5376
5375
|
scheduler;
|
|
5377
|
-
|
|
5376
|
+
options;
|
|
5377
|
+
constructor(fn, scheduler, options) {
|
|
5378
5378
|
this.fn = fn;
|
|
5379
5379
|
this.scheduler = scheduler;
|
|
5380
|
+
this.options = options; // 默认值为'same'
|
|
5380
5381
|
}
|
|
5381
5382
|
run(cb) {
|
|
5382
5383
|
if (!this.active) {
|
|
@@ -5394,6 +5395,18 @@ class ReactiveEffect {
|
|
|
5394
5395
|
}
|
|
5395
5396
|
}
|
|
5396
5397
|
}
|
|
5398
|
+
stop() {
|
|
5399
|
+
if (this.active) {
|
|
5400
|
+
// 清除依赖关系
|
|
5401
|
+
if (this.deps && this.deps.length) {
|
|
5402
|
+
this.deps.forEach((dep) => {
|
|
5403
|
+
dep.delete(this);
|
|
5404
|
+
});
|
|
5405
|
+
this.deps.length = 0;
|
|
5406
|
+
}
|
|
5407
|
+
this.active = false;
|
|
5408
|
+
}
|
|
5409
|
+
}
|
|
5397
5410
|
}
|
|
5398
5411
|
class RefImpl {
|
|
5399
5412
|
_value;
|
|
@@ -5463,9 +5476,7 @@ class Vue {
|
|
|
5463
5476
|
set(target, key, value, receiver) {
|
|
5464
5477
|
const oldValue = target[key];
|
|
5465
5478
|
const result = Reflect.set(target, key, value, receiver);
|
|
5466
|
-
|
|
5467
|
-
that.trigger(target, "set", key, oldValue, value);
|
|
5468
|
-
}
|
|
5479
|
+
that.trigger(target, "set", key, oldValue, value);
|
|
5469
5480
|
return result;
|
|
5470
5481
|
},
|
|
5471
5482
|
});
|
|
@@ -5476,8 +5487,9 @@ class Vue {
|
|
|
5476
5487
|
* 观察被reactive的对象值改变
|
|
5477
5488
|
* @param source 被观察的对象,这里采用函数返回对象
|
|
5478
5489
|
* @param changeCallBack 值改变的回调
|
|
5490
|
+
* @param options 配置项
|
|
5479
5491
|
*/
|
|
5480
|
-
watch(source, changeCallBack) {
|
|
5492
|
+
watch(source, changeCallBack, options) {
|
|
5481
5493
|
let getter;
|
|
5482
5494
|
if (VueUtils.isReactive(source)) {
|
|
5483
5495
|
getter = () => this.traversal(source);
|
|
@@ -5489,17 +5501,35 @@ class Vue {
|
|
|
5489
5501
|
return;
|
|
5490
5502
|
}
|
|
5491
5503
|
let oldValue;
|
|
5504
|
+
const unwatch = () => {
|
|
5505
|
+
effect.stop();
|
|
5506
|
+
};
|
|
5492
5507
|
const job = () => {
|
|
5493
5508
|
const newValue = effect.run((activeEffect) => {
|
|
5494
5509
|
this.activeEffect = activeEffect;
|
|
5495
5510
|
});
|
|
5496
5511
|
changeCallBack(newValue, oldValue);
|
|
5512
|
+
if (options?.once) {
|
|
5513
|
+
// 仅触发一次
|
|
5514
|
+
unwatch();
|
|
5515
|
+
}
|
|
5497
5516
|
oldValue = newValue;
|
|
5498
5517
|
};
|
|
5499
|
-
const effect = new ReactiveEffect(getter, job
|
|
5518
|
+
const effect = new ReactiveEffect(getter, job, {
|
|
5519
|
+
triggerMethod: "not-same",
|
|
5520
|
+
...(options ?? {}),
|
|
5521
|
+
});
|
|
5500
5522
|
oldValue = effect.run((activeEffect) => {
|
|
5501
5523
|
this.activeEffect = activeEffect;
|
|
5502
5524
|
});
|
|
5525
|
+
if (options) {
|
|
5526
|
+
if (options.immediate) {
|
|
5527
|
+
job();
|
|
5528
|
+
}
|
|
5529
|
+
}
|
|
5530
|
+
return {
|
|
5531
|
+
unwatch,
|
|
5532
|
+
};
|
|
5503
5533
|
}
|
|
5504
5534
|
toReactive(value) {
|
|
5505
5535
|
return VueUtils.isObject(value) ? this.reactive(value) : value;
|
|
@@ -5517,28 +5547,40 @@ class Vue {
|
|
|
5517
5547
|
}
|
|
5518
5548
|
return result;
|
|
5519
5549
|
}
|
|
5520
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5521
5550
|
trigger(target, type, key, oldValue, value) {
|
|
5522
5551
|
const depsMap = this.targetMap.get(target);
|
|
5523
5552
|
if (!depsMap)
|
|
5524
5553
|
return;
|
|
5525
5554
|
const effects = depsMap.get(key);
|
|
5526
|
-
this.triggerEffect(effects, "effects");
|
|
5555
|
+
this.triggerEffect(effects, type, "effects", oldValue, value);
|
|
5527
5556
|
}
|
|
5528
|
-
|
|
5529
|
-
triggerEffect(effects, name) {
|
|
5557
|
+
triggerEffect(effects, _type, _name, oldValue, value) {
|
|
5530
5558
|
if (effects) {
|
|
5559
|
+
const isSame = oldValue === value;
|
|
5531
5560
|
effects.forEach((effect) => {
|
|
5532
|
-
if (effect.
|
|
5533
|
-
|
|
5561
|
+
if (effect.options.triggerMethod === "not-same") {
|
|
5562
|
+
if (isSame) {
|
|
5563
|
+
return;
|
|
5564
|
+
}
|
|
5565
|
+
if (effect.scheduler) {
|
|
5566
|
+
effect.scheduler();
|
|
5567
|
+
}
|
|
5568
|
+
else {
|
|
5569
|
+
effect.run();
|
|
5570
|
+
}
|
|
5534
5571
|
}
|
|
5535
|
-
else {
|
|
5536
|
-
effect.
|
|
5572
|
+
else if (effect.options.triggerMethod === "set") {
|
|
5573
|
+
if (effect.scheduler) {
|
|
5574
|
+
effect.scheduler();
|
|
5575
|
+
}
|
|
5576
|
+
else {
|
|
5577
|
+
effect.run();
|
|
5578
|
+
}
|
|
5537
5579
|
}
|
|
5538
5580
|
});
|
|
5539
5581
|
}
|
|
5540
5582
|
}
|
|
5541
|
-
track(target,
|
|
5583
|
+
track(target, _type, key) {
|
|
5542
5584
|
if (!this.activeEffect)
|
|
5543
5585
|
return;
|
|
5544
5586
|
let depsMap = this.targetMap.get(target);
|
|
@@ -8220,14 +8262,39 @@ class Utils {
|
|
|
8220
8262
|
/**
|
|
8221
8263
|
* 自定义的动态响应对象
|
|
8222
8264
|
* @example
|
|
8223
|
-
*
|
|
8224
|
-
*
|
|
8225
|
-
*
|
|
8265
|
+
* const vue = new Utils.Vue();
|
|
8266
|
+
* const reactive = vue.reactive({
|
|
8267
|
+
* name: "",
|
|
8268
|
+
* });
|
|
8269
|
+
* vue.watch(()=>reactive.name, (newValue, oldValue)=>{
|
|
8270
|
+
* console.log("newValue ==> " + newValue);
|
|
8271
|
+
* console.log("oldValue ==> " + oldValue);
|
|
8272
|
+
* })
|
|
8273
|
+
* reactive.name = "测试";
|
|
8274
|
+
* > newValue ==> 测试
|
|
8275
|
+
* > oldValue ==>
|
|
8276
|
+
* reactive.name = "null";
|
|
8277
|
+
* > newValue ==> null
|
|
8278
|
+
* > oldValue ==> 测试
|
|
8279
|
+
* reactive.name = "null";
|
|
8280
|
+
* @example
|
|
8281
|
+
* const vue = new Utils.Vue();
|
|
8282
|
+
* const reactive = vue.reactive({
|
|
8283
|
+
* name: "",
|
|
8284
|
+
* });
|
|
8285
|
+
* vue.watch(()=>reactive.name, (newValue, oldValue)=>{
|
|
8226
8286
|
* console.log("newValue ==> " + newValue);
|
|
8227
8287
|
* console.log("oldValue ==> " + oldValue);
|
|
8288
|
+
* },{
|
|
8289
|
+
* triggerMethod: "set",
|
|
8228
8290
|
* })
|
|
8229
|
-
*
|
|
8230
|
-
* >
|
|
8291
|
+
* reactive.name = "测试";
|
|
8292
|
+
* > newValue ==> 测试
|
|
8293
|
+
* > oldValue ==>
|
|
8294
|
+
* reactive.name = "测试";
|
|
8295
|
+
* > newValue ==> 测试
|
|
8296
|
+
* > oldValue ==> 测试
|
|
8297
|
+
*
|
|
8231
8298
|
*/
|
|
8232
8299
|
Vue = Vue;
|
|
8233
8300
|
ModuleRaid = ModuleRaid;
|