@vue/reactivity 3.3.3 → 3.3.5
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/reactivity.cjs.js +52 -64
- package/dist/reactivity.cjs.prod.js +52 -64
- package/dist/reactivity.d.ts +50 -74
- package/dist/reactivity.esm-browser.js +55 -67
- package/dist/reactivity.esm-browser.prod.js +1 -1
- package/dist/reactivity.esm-bundler.js +76 -88
- package/dist/reactivity.global.js +55 -67
- package/dist/reactivity.global.prod.js +1 -1
- package/package.json +2 -2
package/dist/reactivity.cjs.js
CHANGED
|
@@ -215,7 +215,7 @@ function cleanupEffect(effect2) {
|
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
function effect(fn, options) {
|
|
218
|
-
if (fn.effect) {
|
|
218
|
+
if (fn.effect instanceof ReactiveEffect) {
|
|
219
219
|
fn = fn.effect.fn;
|
|
220
220
|
}
|
|
221
221
|
const _effect = new ReactiveEffect(fn);
|
|
@@ -385,10 +385,6 @@ const isNonTrackableKeys = /* @__PURE__ */ shared.makeMap(`__proto__,__v_isRef,_
|
|
|
385
385
|
const builtInSymbols = new Set(
|
|
386
386
|
/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(shared.isSymbol)
|
|
387
387
|
);
|
|
388
|
-
const get$1 = /* @__PURE__ */ createGetter();
|
|
389
|
-
const shallowGet = /* @__PURE__ */ createGetter(false, true);
|
|
390
|
-
const readonlyGet = /* @__PURE__ */ createGetter(true);
|
|
391
|
-
const shallowReadonlyGet = /* @__PURE__ */ createGetter(true, true);
|
|
392
388
|
const arrayInstrumentations = /* @__PURE__ */ createArrayInstrumentations();
|
|
393
389
|
function createArrayInstrumentations() {
|
|
394
390
|
const instrumentations = {};
|
|
@@ -421,8 +417,13 @@ function hasOwnProperty(key) {
|
|
|
421
417
|
track(obj, "has", key);
|
|
422
418
|
return obj.hasOwnProperty(key);
|
|
423
419
|
}
|
|
424
|
-
|
|
425
|
-
|
|
420
|
+
class BaseReactiveHandler {
|
|
421
|
+
constructor(_isReadonly = false, _shallow = false) {
|
|
422
|
+
this._isReadonly = _isReadonly;
|
|
423
|
+
this._shallow = _shallow;
|
|
424
|
+
}
|
|
425
|
+
get(target, key, receiver) {
|
|
426
|
+
const isReadonly2 = this._isReadonly, shallow = this._shallow;
|
|
426
427
|
if (key === "__v_isReactive") {
|
|
427
428
|
return !isReadonly2;
|
|
428
429
|
} else if (key === "__v_isReadonly") {
|
|
@@ -458,17 +459,18 @@ function createGetter(isReadonly2 = false, shallow = false) {
|
|
|
458
459
|
return isReadonly2 ? readonly(res) : reactive(res);
|
|
459
460
|
}
|
|
460
461
|
return res;
|
|
461
|
-
}
|
|
462
|
+
}
|
|
462
463
|
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
464
|
+
class MutableReactiveHandler extends BaseReactiveHandler {
|
|
465
|
+
constructor(shallow = false) {
|
|
466
|
+
super(false, shallow);
|
|
467
|
+
}
|
|
468
|
+
set(target, key, value, receiver) {
|
|
467
469
|
let oldValue = target[key];
|
|
468
470
|
if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
|
|
469
471
|
return false;
|
|
470
472
|
}
|
|
471
|
-
if (!
|
|
473
|
+
if (!this._shallow) {
|
|
472
474
|
if (!isShallow(value) && !isReadonly(value)) {
|
|
473
475
|
oldValue = toRaw(oldValue);
|
|
474
476
|
value = toRaw(value);
|
|
@@ -488,37 +490,36 @@ function createSetter(shallow = false) {
|
|
|
488
490
|
}
|
|
489
491
|
}
|
|
490
492
|
return result;
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
function deleteProperty(target, key) {
|
|
494
|
-
const hadKey = shared.hasOwn(target, key);
|
|
495
|
-
const oldValue = target[key];
|
|
496
|
-
const result = Reflect.deleteProperty(target, key);
|
|
497
|
-
if (result && hadKey) {
|
|
498
|
-
trigger(target, "delete", key, void 0, oldValue);
|
|
499
493
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
494
|
+
deleteProperty(target, key) {
|
|
495
|
+
const hadKey = shared.hasOwn(target, key);
|
|
496
|
+
const oldValue = target[key];
|
|
497
|
+
const result = Reflect.deleteProperty(target, key);
|
|
498
|
+
if (result && hadKey) {
|
|
499
|
+
trigger(target, "delete", key, void 0, oldValue);
|
|
500
|
+
}
|
|
501
|
+
return result;
|
|
502
|
+
}
|
|
503
|
+
has(target, key) {
|
|
504
|
+
const result = Reflect.has(target, key);
|
|
505
|
+
if (!shared.isSymbol(key) || !builtInSymbols.has(key)) {
|
|
506
|
+
track(target, "has", key);
|
|
507
|
+
}
|
|
508
|
+
return result;
|
|
509
|
+
}
|
|
510
|
+
ownKeys(target) {
|
|
511
|
+
track(
|
|
512
|
+
target,
|
|
513
|
+
"iterate",
|
|
514
|
+
shared.isArray(target) ? "length" : ITERATE_KEY
|
|
515
|
+
);
|
|
516
|
+
return Reflect.ownKeys(target);
|
|
506
517
|
}
|
|
507
|
-
return result;
|
|
508
|
-
}
|
|
509
|
-
function ownKeys(target) {
|
|
510
|
-
track(target, "iterate", shared.isArray(target) ? "length" : ITERATE_KEY);
|
|
511
|
-
return Reflect.ownKeys(target);
|
|
512
518
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
has: has$1,
|
|
518
|
-
ownKeys
|
|
519
|
-
};
|
|
520
|
-
const readonlyHandlers = {
|
|
521
|
-
get: readonlyGet,
|
|
519
|
+
class ReadonlyReactiveHandler extends BaseReactiveHandler {
|
|
520
|
+
constructor(shallow = false) {
|
|
521
|
+
super(true, shallow);
|
|
522
|
+
}
|
|
522
523
|
set(target, key) {
|
|
523
524
|
{
|
|
524
525
|
warn(
|
|
@@ -527,7 +528,7 @@ const readonlyHandlers = {
|
|
|
527
528
|
);
|
|
528
529
|
}
|
|
529
530
|
return true;
|
|
530
|
-
}
|
|
531
|
+
}
|
|
531
532
|
deleteProperty(target, key) {
|
|
532
533
|
{
|
|
533
534
|
warn(
|
|
@@ -537,22 +538,13 @@ const readonlyHandlers = {
|
|
|
537
538
|
}
|
|
538
539
|
return true;
|
|
539
540
|
}
|
|
540
|
-
}
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
get: shallowGet,
|
|
546
|
-
set: shallowSet
|
|
547
|
-
}
|
|
548
|
-
);
|
|
549
|
-
const shallowReadonlyHandlers = /* @__PURE__ */ shared.extend(
|
|
550
|
-
{},
|
|
551
|
-
readonlyHandlers,
|
|
552
|
-
{
|
|
553
|
-
get: shallowReadonlyGet
|
|
554
|
-
}
|
|
541
|
+
}
|
|
542
|
+
const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
|
|
543
|
+
const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
|
|
544
|
+
const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(
|
|
545
|
+
true
|
|
555
546
|
);
|
|
547
|
+
const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true);
|
|
556
548
|
|
|
557
549
|
const toShallow = (value) => value;
|
|
558
550
|
const getProto = (v) => Reflect.getPrototypeOf(v);
|
|
@@ -561,7 +553,7 @@ function get(target, key, isReadonly = false, isShallow = false) {
|
|
|
561
553
|
const rawTarget = toRaw(target);
|
|
562
554
|
const rawKey = toRaw(key);
|
|
563
555
|
if (!isReadonly) {
|
|
564
|
-
if (key
|
|
556
|
+
if (shared.hasChanged(key, rawKey)) {
|
|
565
557
|
track(rawTarget, "get", key);
|
|
566
558
|
}
|
|
567
559
|
track(rawTarget, "get", rawKey);
|
|
@@ -581,7 +573,7 @@ function has(key, isReadonly = false) {
|
|
|
581
573
|
const rawTarget = toRaw(target);
|
|
582
574
|
const rawKey = toRaw(key);
|
|
583
575
|
if (!isReadonly) {
|
|
584
|
-
if (key
|
|
576
|
+
if (shared.hasChanged(key, rawKey)) {
|
|
585
577
|
track(rawTarget, "has", key);
|
|
586
578
|
}
|
|
587
579
|
track(rawTarget, "has", rawKey);
|
|
@@ -1111,11 +1103,7 @@ function toRef(source, key, defaultValue) {
|
|
|
1111
1103
|
}
|
|
1112
1104
|
function propertyToRef(source, key, defaultValue) {
|
|
1113
1105
|
const val = source[key];
|
|
1114
|
-
return isRef(val) ? val : new ObjectRefImpl(
|
|
1115
|
-
source,
|
|
1116
|
-
key,
|
|
1117
|
-
defaultValue
|
|
1118
|
-
);
|
|
1106
|
+
return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
|
|
1119
1107
|
}
|
|
1120
1108
|
|
|
1121
1109
|
class ComputedRefImpl {
|
|
@@ -205,7 +205,7 @@ function cleanupEffect(effect2) {
|
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
function effect(fn, options) {
|
|
208
|
-
if (fn.effect) {
|
|
208
|
+
if (fn.effect instanceof ReactiveEffect) {
|
|
209
209
|
fn = fn.effect.fn;
|
|
210
210
|
}
|
|
211
211
|
const _effect = new ReactiveEffect(fn);
|
|
@@ -360,10 +360,6 @@ const isNonTrackableKeys = /* @__PURE__ */ shared.makeMap(`__proto__,__v_isRef,_
|
|
|
360
360
|
const builtInSymbols = new Set(
|
|
361
361
|
/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(shared.isSymbol)
|
|
362
362
|
);
|
|
363
|
-
const get$1 = /* @__PURE__ */ createGetter();
|
|
364
|
-
const shallowGet = /* @__PURE__ */ createGetter(false, true);
|
|
365
|
-
const readonlyGet = /* @__PURE__ */ createGetter(true);
|
|
366
|
-
const shallowReadonlyGet = /* @__PURE__ */ createGetter(true, true);
|
|
367
363
|
const arrayInstrumentations = /* @__PURE__ */ createArrayInstrumentations();
|
|
368
364
|
function createArrayInstrumentations() {
|
|
369
365
|
const instrumentations = {};
|
|
@@ -396,8 +392,13 @@ function hasOwnProperty(key) {
|
|
|
396
392
|
track(obj, "has", key);
|
|
397
393
|
return obj.hasOwnProperty(key);
|
|
398
394
|
}
|
|
399
|
-
|
|
400
|
-
|
|
395
|
+
class BaseReactiveHandler {
|
|
396
|
+
constructor(_isReadonly = false, _shallow = false) {
|
|
397
|
+
this._isReadonly = _isReadonly;
|
|
398
|
+
this._shallow = _shallow;
|
|
399
|
+
}
|
|
400
|
+
get(target, key, receiver) {
|
|
401
|
+
const isReadonly2 = this._isReadonly, shallow = this._shallow;
|
|
401
402
|
if (key === "__v_isReactive") {
|
|
402
403
|
return !isReadonly2;
|
|
403
404
|
} else if (key === "__v_isReadonly") {
|
|
@@ -433,17 +434,18 @@ function createGetter(isReadonly2 = false, shallow = false) {
|
|
|
433
434
|
return isReadonly2 ? readonly(res) : reactive(res);
|
|
434
435
|
}
|
|
435
436
|
return res;
|
|
436
|
-
}
|
|
437
|
+
}
|
|
437
438
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
439
|
+
class MutableReactiveHandler extends BaseReactiveHandler {
|
|
440
|
+
constructor(shallow = false) {
|
|
441
|
+
super(false, shallow);
|
|
442
|
+
}
|
|
443
|
+
set(target, key, value, receiver) {
|
|
442
444
|
let oldValue = target[key];
|
|
443
445
|
if (isReadonly(oldValue) && isRef(oldValue) && !isRef(value)) {
|
|
444
446
|
return false;
|
|
445
447
|
}
|
|
446
|
-
if (!
|
|
448
|
+
if (!this._shallow) {
|
|
447
449
|
if (!isShallow(value) && !isReadonly(value)) {
|
|
448
450
|
oldValue = toRaw(oldValue);
|
|
449
451
|
value = toRaw(value);
|
|
@@ -463,59 +465,49 @@ function createSetter(shallow = false) {
|
|
|
463
465
|
}
|
|
464
466
|
}
|
|
465
467
|
return result;
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
function deleteProperty(target, key) {
|
|
469
|
-
const hadKey = shared.hasOwn(target, key);
|
|
470
|
-
target[key];
|
|
471
|
-
const result = Reflect.deleteProperty(target, key);
|
|
472
|
-
if (result && hadKey) {
|
|
473
|
-
trigger(target, "delete", key, void 0);
|
|
474
468
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
469
|
+
deleteProperty(target, key) {
|
|
470
|
+
const hadKey = shared.hasOwn(target, key);
|
|
471
|
+
target[key];
|
|
472
|
+
const result = Reflect.deleteProperty(target, key);
|
|
473
|
+
if (result && hadKey) {
|
|
474
|
+
trigger(target, "delete", key, void 0);
|
|
475
|
+
}
|
|
476
|
+
return result;
|
|
477
|
+
}
|
|
478
|
+
has(target, key) {
|
|
479
|
+
const result = Reflect.has(target, key);
|
|
480
|
+
if (!shared.isSymbol(key) || !builtInSymbols.has(key)) {
|
|
481
|
+
track(target, "has", key);
|
|
482
|
+
}
|
|
483
|
+
return result;
|
|
484
|
+
}
|
|
485
|
+
ownKeys(target) {
|
|
486
|
+
track(
|
|
487
|
+
target,
|
|
488
|
+
"iterate",
|
|
489
|
+
shared.isArray(target) ? "length" : ITERATE_KEY
|
|
490
|
+
);
|
|
491
|
+
return Reflect.ownKeys(target);
|
|
481
492
|
}
|
|
482
|
-
return result;
|
|
483
|
-
}
|
|
484
|
-
function ownKeys(target) {
|
|
485
|
-
track(target, "iterate", shared.isArray(target) ? "length" : ITERATE_KEY);
|
|
486
|
-
return Reflect.ownKeys(target);
|
|
487
493
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
has: has$1,
|
|
493
|
-
ownKeys
|
|
494
|
-
};
|
|
495
|
-
const readonlyHandlers = {
|
|
496
|
-
get: readonlyGet,
|
|
494
|
+
class ReadonlyReactiveHandler extends BaseReactiveHandler {
|
|
495
|
+
constructor(shallow = false) {
|
|
496
|
+
super(true, shallow);
|
|
497
|
+
}
|
|
497
498
|
set(target, key) {
|
|
498
499
|
return true;
|
|
499
|
-
}
|
|
500
|
+
}
|
|
500
501
|
deleteProperty(target, key) {
|
|
501
502
|
return true;
|
|
502
503
|
}
|
|
503
|
-
}
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
get: shallowGet,
|
|
509
|
-
set: shallowSet
|
|
510
|
-
}
|
|
511
|
-
);
|
|
512
|
-
const shallowReadonlyHandlers = /* @__PURE__ */ shared.extend(
|
|
513
|
-
{},
|
|
514
|
-
readonlyHandlers,
|
|
515
|
-
{
|
|
516
|
-
get: shallowReadonlyGet
|
|
517
|
-
}
|
|
504
|
+
}
|
|
505
|
+
const mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler();
|
|
506
|
+
const readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler();
|
|
507
|
+
const shallowReactiveHandlers = /* @__PURE__ */ new MutableReactiveHandler(
|
|
508
|
+
true
|
|
518
509
|
);
|
|
510
|
+
const shallowReadonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler(true);
|
|
519
511
|
|
|
520
512
|
const toShallow = (value) => value;
|
|
521
513
|
const getProto = (v) => Reflect.getPrototypeOf(v);
|
|
@@ -524,7 +516,7 @@ function get(target, key, isReadonly = false, isShallow = false) {
|
|
|
524
516
|
const rawTarget = toRaw(target);
|
|
525
517
|
const rawKey = toRaw(key);
|
|
526
518
|
if (!isReadonly) {
|
|
527
|
-
if (key
|
|
519
|
+
if (shared.hasChanged(key, rawKey)) {
|
|
528
520
|
track(rawTarget, "get", key);
|
|
529
521
|
}
|
|
530
522
|
track(rawTarget, "get", rawKey);
|
|
@@ -544,7 +536,7 @@ function has(key, isReadonly = false) {
|
|
|
544
536
|
const rawTarget = toRaw(target);
|
|
545
537
|
const rawKey = toRaw(key);
|
|
546
538
|
if (!isReadonly) {
|
|
547
|
-
if (key
|
|
539
|
+
if (shared.hasChanged(key, rawKey)) {
|
|
548
540
|
track(rawTarget, "has", key);
|
|
549
541
|
}
|
|
550
542
|
track(rawTarget, "has", rawKey);
|
|
@@ -1038,11 +1030,7 @@ function toRef(source, key, defaultValue) {
|
|
|
1038
1030
|
}
|
|
1039
1031
|
function propertyToRef(source, key, defaultValue) {
|
|
1040
1032
|
const val = source[key];
|
|
1041
|
-
return isRef(val) ? val : new ObjectRefImpl(
|
|
1042
|
-
source,
|
|
1043
|
-
key,
|
|
1044
|
-
defaultValue
|
|
1045
|
-
);
|
|
1033
|
+
return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
|
|
1046
1034
|
}
|
|
1047
1035
|
|
|
1048
1036
|
class ComputedRefImpl {
|
package/dist/reactivity.d.ts
CHANGED
|
@@ -234,17 +234,9 @@ export declare const enum TriggerOpTypes {
|
|
|
234
234
|
|
|
235
235
|
export declare class EffectScope {
|
|
236
236
|
detached: boolean;
|
|
237
|
-
/* removed internal: _active */
|
|
238
|
-
/* removed internal: effects */
|
|
239
|
-
/* removed internal: cleanups */
|
|
240
|
-
/* removed internal: parent */
|
|
241
|
-
/* removed internal: scopes */
|
|
242
|
-
/* removed internal: index */
|
|
243
237
|
constructor(detached?: boolean);
|
|
244
238
|
get active(): boolean;
|
|
245
239
|
run<T>(fn: () => T): T | undefined;
|
|
246
|
-
/* removed internal: on */
|
|
247
|
-
/* removed internal: off */
|
|
248
240
|
stop(fromParent?: boolean): void;
|
|
249
241
|
}
|
|
250
242
|
/**
|
|
@@ -272,69 +264,6 @@ export declare function getCurrentScope(): EffectScope | undefined;
|
|
|
272
264
|
*/
|
|
273
265
|
export declare function onScopeDispose(fn: () => void): void;
|
|
274
266
|
|
|
275
|
-
declare const ComputedRefSymbol: unique symbol;
|
|
276
|
-
export interface ComputedRef<T = any> extends WritableComputedRef<T> {
|
|
277
|
-
readonly value: T;
|
|
278
|
-
[ComputedRefSymbol]: true;
|
|
279
|
-
}
|
|
280
|
-
export interface WritableComputedRef<T> extends Ref<T> {
|
|
281
|
-
readonly effect: ReactiveEffect<T>;
|
|
282
|
-
}
|
|
283
|
-
export type ComputedGetter<T> = (...args: any[]) => T;
|
|
284
|
-
export type ComputedSetter<T> = (v: T) => void;
|
|
285
|
-
export interface WritableComputedOptions<T> {
|
|
286
|
-
get: ComputedGetter<T>;
|
|
287
|
-
set: ComputedSetter<T>;
|
|
288
|
-
}
|
|
289
|
-
declare class ComputedRefImpl<T> {
|
|
290
|
-
private readonly _setter;
|
|
291
|
-
dep?: Dep;
|
|
292
|
-
private _value;
|
|
293
|
-
readonly effect: ReactiveEffect<T>;
|
|
294
|
-
readonly __v_isRef = true;
|
|
295
|
-
readonly [ReactiveFlags.IS_READONLY]: boolean;
|
|
296
|
-
_dirty: boolean;
|
|
297
|
-
_cacheable: boolean;
|
|
298
|
-
constructor(getter: ComputedGetter<T>, _setter: ComputedSetter<T>, isReadonly: boolean, isSSR: boolean);
|
|
299
|
-
get value(): T;
|
|
300
|
-
set value(newValue: T);
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Takes a getter function and returns a readonly reactive ref object for the
|
|
304
|
-
* returned value from the getter. It can also take an object with get and set
|
|
305
|
-
* functions to create a writable ref object.
|
|
306
|
-
*
|
|
307
|
-
* @example
|
|
308
|
-
* ```js
|
|
309
|
-
* // Creating a readonly computed ref:
|
|
310
|
-
* const count = ref(1)
|
|
311
|
-
* const plusOne = computed(() => count.value + 1)
|
|
312
|
-
*
|
|
313
|
-
* console.log(plusOne.value) // 2
|
|
314
|
-
* plusOne.value++ // error
|
|
315
|
-
* ```
|
|
316
|
-
*
|
|
317
|
-
* ```js
|
|
318
|
-
* // Creating a writable computed ref:
|
|
319
|
-
* const count = ref(1)
|
|
320
|
-
* const plusOne = computed({
|
|
321
|
-
* get: () => count.value + 1,
|
|
322
|
-
* set: (val) => {
|
|
323
|
-
* count.value = val - 1
|
|
324
|
-
* }
|
|
325
|
-
* })
|
|
326
|
-
*
|
|
327
|
-
* plusOne.value = 1
|
|
328
|
-
* console.log(count.value) // 0
|
|
329
|
-
* ```
|
|
330
|
-
*
|
|
331
|
-
* @param getter - Function that produces the next value.
|
|
332
|
-
* @param debugOptions - For debugging. See {@link https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging}.
|
|
333
|
-
* @see {@link https://vuejs.org/api/reactivity-core.html#computed}
|
|
334
|
-
*/
|
|
335
|
-
export declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
|
|
336
|
-
export declare function computed<T>(options: WritableComputedOptions<T>, debugOptions?: DebuggerOptions): WritableComputedRef<T>;
|
|
337
|
-
|
|
338
267
|
export type EffectScheduler = (...args: any[]) => any;
|
|
339
268
|
export type DebuggerEvent = {
|
|
340
269
|
effect: ReactiveEffect;
|
|
@@ -354,9 +283,6 @@ export declare class ReactiveEffect<T = any> {
|
|
|
354
283
|
active: boolean;
|
|
355
284
|
deps: Dep[];
|
|
356
285
|
parent: ReactiveEffect | undefined;
|
|
357
|
-
/* removed internal: computed */
|
|
358
|
-
/* removed internal: allowRecurse */
|
|
359
|
-
/* removed internal: deferStop */
|
|
360
286
|
onStop?: () => void;
|
|
361
287
|
onTrack?: (event: DebuggerEvent) => void;
|
|
362
288
|
onTrigger?: (event: DebuggerEvent) => void;
|
|
@@ -672,5 +598,55 @@ type UnwrapRefSimple<T> = T extends Function | CollectionTypes | BaseTypes | Ref
|
|
|
672
598
|
[P in keyof T]: P extends symbol ? T[P] : UnwrapRef<T[P]>;
|
|
673
599
|
} : T;
|
|
674
600
|
|
|
601
|
+
declare const ComputedRefSymbol: unique symbol;
|
|
602
|
+
export interface ComputedRef<T = any> extends WritableComputedRef<T> {
|
|
603
|
+
readonly value: T;
|
|
604
|
+
[ComputedRefSymbol]: true;
|
|
605
|
+
}
|
|
606
|
+
export interface WritableComputedRef<T> extends Ref<T> {
|
|
607
|
+
readonly effect: ReactiveEffect<T>;
|
|
608
|
+
}
|
|
609
|
+
export type ComputedGetter<T> = (...args: any[]) => T;
|
|
610
|
+
export type ComputedSetter<T> = (v: T) => void;
|
|
611
|
+
export interface WritableComputedOptions<T> {
|
|
612
|
+
get: ComputedGetter<T>;
|
|
613
|
+
set: ComputedSetter<T>;
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Takes a getter function and returns a readonly reactive ref object for the
|
|
617
|
+
* returned value from the getter. It can also take an object with get and set
|
|
618
|
+
* functions to create a writable ref object.
|
|
619
|
+
*
|
|
620
|
+
* @example
|
|
621
|
+
* ```js
|
|
622
|
+
* // Creating a readonly computed ref:
|
|
623
|
+
* const count = ref(1)
|
|
624
|
+
* const plusOne = computed(() => count.value + 1)
|
|
625
|
+
*
|
|
626
|
+
* console.log(plusOne.value) // 2
|
|
627
|
+
* plusOne.value++ // error
|
|
628
|
+
* ```
|
|
629
|
+
*
|
|
630
|
+
* ```js
|
|
631
|
+
* // Creating a writable computed ref:
|
|
632
|
+
* const count = ref(1)
|
|
633
|
+
* const plusOne = computed({
|
|
634
|
+
* get: () => count.value + 1,
|
|
635
|
+
* set: (val) => {
|
|
636
|
+
* count.value = val - 1
|
|
637
|
+
* }
|
|
638
|
+
* })
|
|
639
|
+
*
|
|
640
|
+
* plusOne.value = 1
|
|
641
|
+
* console.log(count.value) // 0
|
|
642
|
+
* ```
|
|
643
|
+
*
|
|
644
|
+
* @param getter - Function that produces the next value.
|
|
645
|
+
* @param debugOptions - For debugging. See {@link https://vuejs.org/guide/extras/reactivity-in-depth.html#computed-debugging}.
|
|
646
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#computed}
|
|
647
|
+
*/
|
|
648
|
+
export declare function computed<T>(getter: ComputedGetter<T>, debugOptions?: DebuggerOptions): ComputedRef<T>;
|
|
649
|
+
export declare function computed<T>(options: WritableComputedOptions<T>, debugOptions?: DebuggerOptions): WritableComputedRef<T>;
|
|
650
|
+
|
|
675
651
|
export declare function deferredComputed<T>(getter: () => T): ComputedRef<T>;
|
|
676
652
|
|