@lytjs/reactivity 5.0.1 → 6.4.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/README.md +327 -202
- package/dist/async.cjs +276 -0
- package/dist/async.cjs.map +1 -0
- package/dist/async.d.cts +32 -0
- package/dist/async.d.ts +32 -0
- package/dist/async.mjs +273 -0
- package/dist/async.mjs.map +1 -0
- package/dist/index.cjs +1679 -1
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +226 -0
- package/dist/index.d.ts +226 -0
- package/dist/index.mjs +1612 -1
- package/dist/index.mjs.map +1 -0
- package/dist/ref-CwOCKoy2.d.cts +42 -0
- package/dist/ref-CwOCKoy2.d.ts +42 -0
- package/dist/scope-BC3djHz7.d.cts +345 -0
- package/dist/scope-CTxSo201.d.ts +345 -0
- package/dist/scope.cjs +74 -0
- package/dist/scope.cjs.map +1 -0
- package/dist/scope.d.cts +2 -0
- package/dist/scope.d.ts +2 -0
- package/dist/scope.mjs +70 -0
- package/dist/scope.mjs.map +1 -0
- package/dist/signal-DWrUYmvd.d.cts +109 -0
- package/dist/signal-DWrUYmvd.d.ts +109 -0
- package/dist/signal-component.cjs +39 -0
- package/dist/signal-component.cjs.map +1 -0
- package/dist/signal-component.d.cts +31 -0
- package/dist/signal-component.d.ts +31 -0
- package/dist/signal-component.mjs +35 -0
- package/dist/signal-component.mjs.map +1 -0
- package/dist/signal.cjs +350 -1
- package/dist/signal.cjs.map +1 -0
- package/dist/signal.d.cts +1 -0
- package/dist/signal.d.ts +1 -0
- package/dist/signal.mjs +334 -1
- package/dist/signal.mjs.map +1 -0
- package/package.json +54 -31
- package/dist/types/computed.d.ts +0 -70
- package/dist/types/computed.d.ts.map +0 -1
- package/dist/types/effect.d.ts +0 -157
- package/dist/types/effect.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -21
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/reactive.d.ts +0 -98
- package/dist/types/reactive.d.ts.map +0 -1
- package/dist/types/ref.d.ts +0 -128
- package/dist/types/ref.d.ts.map +0 -1
- package/dist/types/scheduler.d.ts +0 -44
- package/dist/types/scheduler.d.ts.map +0 -1
- package/dist/types/signal-component.d.ts +0 -45
- package/dist/types/signal-component.d.ts.map +0 -1
- package/dist/types/signal.d.ts +0 -87
- package/dist/types/signal.d.ts.map +0 -1
- package/dist/types/watch.d.ts +0 -125
- package/dist/types/watch.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1,1679 @@
|
|
|
1
|
-
"use strict";var N=Object.defineProperty;var Ve=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var Ie=Object.prototype.hasOwnProperty;var Ke=(e,t)=>{for(var n in t)N(e,n,{get:t[n],enumerable:!0})},Ae=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Fe(t))!Ie.call(e,o)&&o!==n&&N(e,o,{get:()=>t[o],enumerable:!(r=Ve(t,o))||r.enumerable});return e};var Me=e=>Ae(N({},"__esModule",{value:!0}),e);var Ue={};Ke(Ue,{ITERATE_KEY:()=>S,ReactiveEffect:()=>d,activeEffect:()=>c,batch:()=>we,clearQueue:()=>x.clearQueue,computed:()=>he,computedSignal:()=>Se,effect:()=>Z,enterSignalComponentContext:()=>Oe,hasPendingJob:()=>x.hasPendingJob,isReactive:()=>w,isReadonly:()=>J,isRef:()=>h,markReadOnly:()=>fe,markSkip:()=>ce,nextTick:()=>R.nextTick,onSignalCleanup:()=>We,pauseTracking:()=>K,queueJob:()=>x.queueJob,queuePostFlushCb:()=>x.queuePostFlushCb,rawSymbol:()=>T,reactive:()=>W,reactiveFlag:()=>v,readonly:()=>H,readonlyFlag:()=>y,ref:()=>le,refSymbol:()=>_,resetTracking:()=>A,shallowReactive:()=>ae,shallowRef:()=>de,shallowRefSymbol:()=>U,signal:()=>G,signalEffect:()=>ve,stop:()=>ee,toRaw:()=>m,toRef:()=>L,toRefs:()=>ye,track:()=>f,trigger:()=>u,triggerRef:()=>Te,unref:()=>be,untrack:()=>ge,useSignal:()=>je,useSignalState:()=>ke,watch:()=>me,watchEffect:()=>xe});module.exports=Me(Ue);var c=null,k=[],De=0,Y=new WeakMap,d=class{constructor(t,n={}){this.active=!0;this.deps=new Set;this.fn=t,this.scheduler=n.scheduler,this.beforeRun=n.beforeRun,this.afterRun=n.afterRun,this.lazy=n.lazy,this.id=De++}run(){var t,n;if(!this.active)return this.fn();if(k.includes(this))return this.fn();try{return(t=this.beforeRun)==null||t.call(this),k.push(this),c=this,B(this),this.fn()}finally{(n=this.afterRun)==null||n.call(this),k.pop(),c=k[k.length-1]||null}}stop(){this.active&&(B(this),this.onStop&&this.onStop(),this.active=!1)}},I=!0,X=[];function K(){X.push(I),I=!1}function A(){let e=X.pop();I=e===void 0?!0:e}function B(e){let{deps:t}=e;for(let n of t)n.delete(e);t.clear()}function f(e,t){if(!I||!c)return;let n=Y.get(e);n||(n=new Map,Y.set(e,n));let r=n.get(t);r||(r=new Set,n.set(t,r)),r.has(c)||(r.add(c),c.deps.add(r))}function u(e,t,n,r){let o=Y.get(e);if(!o)return;let i=new Set,s=a=>{if(a)for(let p of a)(p!==c||p.allowRecurse)&&i.add(p)};if(s(o.get(t)),(n==="add"||n==="delete")&&s(o.get(S)),n==="set"&&Array.isArray(e)){let a=o.get("length");a&&typeof t=="number"&&t<e.length&&s(a)}for(let a of i)a.scheduler?a.scheduler(a):a.run()}var S=Symbol("iterate");function Z(e,t={}){let n=new d(e,t);t.lazy||n.run();let r=n.run.bind(n);return r.effect=n,r.stop=()=>n.stop(),r}function ee(e){var t;(t=e==null?void 0:e.effect)==null||t.stop()}var y=Symbol("readonly"),T=Symbol("raw"),v=Symbol("reactive"),oe=Symbol("skip"),te=new WeakMap,ne=new WeakMap,re=new WeakMap;function O(e){return e!==null&&typeof e=="object"}function ie(e,t){return!Object.is(e,t)}function M(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var D={};["includes","indexOf","lastIndexOf"].forEach(e=>{D[e]=function(...t){let n=m(this);for(let r=0;r<n.length;r++)f(n,String(r));return f(n,"length"),n[e](...t)}});["push","pop","shift","unshift","splice","sort","reverse"].forEach(e=>{D[e]=function(...t){K();let n=Array.prototype[e].apply(this,t);return A(),u(m(this),"length","set",m(this).length),n}});var He={get(e,t,n){if(t===T)return e;if(t===v)return!0;if(Array.isArray(e)&&D.hasOwnProperty(t))return D[t];f(e,t);let r=Reflect.get(e,t,n);return t===y?e[y]===!0:!O(r)||e[oe]?r:W(r)},set(e,t,n,r){let o=e[t],i=Array.isArray(e)&&se(t)?Number(t)<e.length:M(e,t),s=Reflect.set(e,t,n,r);return(e===(r==null?void 0:r[T])||e===m(r))&&(i?ie(n,o)&&u(e,t,"set",n):u(e,t,"add",n)),s},deleteProperty(e,t){let n=M(e,t),r=Reflect.deleteProperty(e,t);return r&&n&&u(e,t,"delete"),r},has(e,t){return f(e,t),Reflect.has(e,t)},ownKeys(e){return f(e,S),Reflect.ownKeys(e)}},ze={get(e,t,n){if(t===T)return e;if(t===v||t===y)return!0;f(e,t);let r=Reflect.get(e,t,n);return O(r)?H(r):r},set(e,t,n,r){return!1},deleteProperty(e,t){return!1},has(e,t){return f(e,t),Reflect.has(e,t)},ownKeys(e){return f(e,S),Reflect.ownKeys(e)}},Ge={get(e,t,n){return t===T?e:t===v?!0:(f(e,t),Reflect.get(e,t,n))},set(e,t,n,r){let o=e[t],i=Array.isArray(e)&&se(t)?Number(t)<e.length:M(e,t),s=Reflect.set(e,t,n,r);return(e===(r==null?void 0:r[T])||e===m(r))&&(i?ie(n,o)&&u(e,t,"set",n):u(e,t,"add",n)),s},deleteProperty(e,t){let n=M(e,t),r=Reflect.deleteProperty(e,t);return r&&n&&u(e,t,"delete"),r},has(e,t){return f(e,t),Reflect.has(e,t)},ownKeys(e){return f(e,S),Reflect.ownKeys(e)}};function se(e){return typeof e=="string"&&e!=="NaN"&&e[0]!=="-"&&""+parseInt(e,10)===e}function W(e,t={}){if(!O(e)||e[v])return e;if(e[y])return H(e);let n=te.get(e);if(n)return n;let r=new Proxy(e,He);return te.set(e,r),r}function H(e){if(!O(e))return e;let t=ne.get(e);if(t)return t;e[y]=!0;let n=new Proxy(e,ze);return ne.set(e,n),n}function ae(e){if(!O(e))return e;let t=re.get(e);if(t)return t;let n=new Proxy(e,Ge);return re.set(e,n),n}function m(e){let t=e&&e[T];return t?m(t):e}function w(e){return J(e)?w(e[T]):!!(e&&e[v])}function J(e){return!!(e&&e[y])}function fe(e){return e[y]=!0,e}function ce(e){return e[oe]=!0,e}var ue=require("@lytjs/common"),_=Symbol("ref"),U=Symbol("shallowRef"),q=new WeakMap;function Ne(e){return q.get(e)||e}function le(e){if(h(e))return e;let t={_value:pe(e),_rawValue:e,__v_isRef:!0,[_]:!0},n=new Proxy(t,Ye);return q.set(n,t),n}function pe(e){return(0,ue.isObject)(e)?W(e):e}var Ye={get(e,t,n){return t==="value"?(f(e,"value"),e._value):t===_||t==="__v_isRef"?!0:t==="_rawValue"?e._rawValue:Reflect.get(e,t,n)},set(e,t,n,r){if(t==="value"){let o=e._rawValue;return Object.is(o,n)||(e._rawValue=n,e._value=pe(n),u(e,"value","set",n)),!0}return Reflect.set(e,t,n,r)}};function de(e){if(h(e))return e;let t={_value:e,_rawValue:e,__v_isRef:!0,__v_isShallow:!0,[_]:!0,[U]:!0},n=new Proxy(t,Je);return q.set(n,t),n}var Je={get(e,t,n){return t==="value"?(f(e,"value"),e._value):t===_||t==="__v_isRef"||t==="__v_isShallow"?!0:t==="_rawValue"?e._rawValue:Reflect.get(e,t,n)},set(e,t,n,r){if(t==="value"){let o=e._rawValue;return Object.is(o,n)||(e._rawValue=n,e._value=n,u(e,"value","set",n)),!0}return Reflect.set(e,t,n,r)}};function h(e){return!!(e&&e.__v_isRef===!0)}function be(e){return h(e)?e.value:e}function L(e,t){let n=e[t];return h(n)?n:new Proxy({_obj:e,_key:t,__v_isRef:!0},{get(r,o,i){return o==="value"?r._obj[r._key]:o==="__v_isRef"?!0:Reflect.get(r,o,i)},set(r,o,i,s){return o==="value"?(r._obj[r._key]=i,!0):Reflect.set(r,o,i,s)}})}function ye(e){let t={};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=L(e,n));return t}function Te(e){let t=Ne(e);u(t,"value","set",t._rawValue)}var $=class{constructor(t,n){this._dirty=!0;this.__v_isRef=!0;this.deps=new Set;this._setter=n,this._effect=new d(t,{scheduler:()=>{this._dirty||(this._dirty=!0,this.triggerDep())},lazy:!0}),this._value=void 0}get value(){return f(this,"value"),c&&!this.deps.has(c)&&(this.deps.add(c),c.deps.add(this.deps)),this._dirty&&(this._value=this._effect.run(),this._dirty=!1),this._value}set value(t){this._setter&&this._setter(t)}triggerDep(){for(let t of this.deps)t.scheduler?t.scheduler(t):t.run()}};function he(e){let t,n;return typeof e=="function"?(t=e,n=void 0):(t=e.get,n=e.set),new $(t,n)}var R=require("@lytjs/common");function P(e,t=1/0,n){if(!(0,R.isObject)(e)||t<=0||(n||(n=new Set),n.has(e)))return e;if(n.add(e),h(e))P(e.value,t-1,n);else if(Array.isArray(e))for(let r=0;r<e.length;r++)P(e[r],t-1,n);else for(let r of Object.keys(e))P(e[r],t-1,n);return e}function Re(e){return h(e)?()=>e.value:w(e)?()=>P(e):typeof e=="function"?e:()=>P(e)}function me(e,t,n={}){let r,o=!1;if(Array.isArray(e)){o=!0;let l=e.map(j=>Re(j));r=()=>l.map(j=>j())}else r=Re(e);w(e)&&n.deep!==!1&&(n.deep=!0);let i=o?[]:void 0,s,a=l=>{s=l},p=()=>{s&&(s(),s=void 0);let l=E.run();(o?l.some((j,Pe)=>!Object.is(j,i[Pe])):!Object.is(l,i)||n.deep&&(0,R.isObject)(l))&&(t(l,o?[...i]:i,a),i=o?[...l]:l)},E=new d(r,{lazy:!0,scheduler:()=>{n.flush==="sync"?p():(0,R.queueJob)(p)}});return n.immediate?p():i=E.run(),()=>{E.stop()}}function xe(e,t={}){let n,r=()=>{n&&(n(),n=void 0),e(i=>{n=i})},o=new d(r,{scheduler:()=>{t.flush==="sync"?r():(0,R.queueJob)(r)}});return o.run(),()=>{o.stop(),n&&(n(),n=void 0)}}var x=require("@lytjs/common");var z=require("@lytjs/common"),b=null,V=!1,F=0,g=new Set,Q=!1;function G(e){let t=e,n=new Set,r=function(){return b&&!V&&n.add(b),t};return r.set=function(o){Object.is(t,o)||(t=o,Ce(n))},r.update=function(o){r.set(o(t))},r._subscribe=function(o){n.add(o)},r._unsubscribe=function(o){n.delete(o)},r.dispose=function(){n.clear()},r}function Se(e){let t,n=!0,r=!1,o=new Set,i=new Set,s=function(){if(b&&!V&&i.add(b),n){if(r)throw new z.LytError(z.LytErrorCodes.LYT_REACTIVITY_CIRCULAR_DEPENDENCY,"computed \u5728\u5176\u81EA\u8EAB\u7684\u8BA1\u7B97\u56FE\u4E2D");r=!0;for(let l of o)l._unsubscribe(s);o.clear();let E=b;b=s;try{t=e()}finally{b=E,r=!1}n=!1}return t},a={_dirty:!1,notify(){n=!0,Ce(i)}};return s.notify=a.notify.bind(a),s._dirty=!1,s._subscribe=function(p){i.add(p)},s._unsubscribe=function(p){i.delete(p)},s}function ve(e){let t=null,n=!1,r=new Set,o=()=>{if(n)return;t&&(t(),t=null);for(let a of r)a._unsubscribe(i);r.clear();let s=b;b=i;try{e(a=>{t=a})}finally{b=s}},i={_dirty:!1,notify(){F>0?g.add(i):o()}};return o(),()=>{n=!0,t&&(t(),t=null);for(let s of r)s._unsubscribe(i);r.clear(),g.delete(i)}}function we(e){F++;try{e()}finally{F--,F===0&&_e()}}function _e(){if(!Q){Q=!0;try{let e=new Set(g);g.clear();for(let t of e)t.notify();g.size>0&&_e()}finally{Q=!1}}}function ge(e){let t=V;V=!0;try{return e()}finally{V=t}}function Ce(e){if(F>0)for(let t of e)g.add(t);else for(let t of e)t.notify()}var C=[];function Ee(){return C.length>0?C[C.length-1]:null}function je(e){return e()}function ke(e){let t=G(e),n=o=>t.set(o),r=Ee();return[t,n]}function Oe(){let e={_cleanupFns:[]};return C.push(e),()=>{for(let n of e._cleanupFns)n();e._cleanupFns.length=0;let t=C.indexOf(e);t!==-1&&C.splice(t,1)}}function We(e){let t=Ee();t&&t._cleanupFns.push(e)}
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var commonIs = require('@lytjs/common-is');
|
|
4
|
+
var commonError = require('@lytjs/common-error');
|
|
5
|
+
var commonAssertions = require('@lytjs/common-assertions');
|
|
6
|
+
var commonConstants = require('@lytjs/common-constants');
|
|
7
|
+
var commonScheduler = require('@lytjs/common-scheduler');
|
|
8
|
+
|
|
9
|
+
// src/reactive.ts
|
|
10
|
+
var RefSymbol = /* @__PURE__ */ Symbol(void 0);
|
|
11
|
+
var ShallowRefSymbol = /* @__PURE__ */ Symbol(void 0);
|
|
12
|
+
var ComputedRefSymbol = /* @__PURE__ */ Symbol(void 0);
|
|
13
|
+
var ReactiveSymbol = /* @__PURE__ */ Symbol(void 0);
|
|
14
|
+
var ReadonlySymbol = /* @__PURE__ */ Symbol(void 0);
|
|
15
|
+
var SignalSymbol = /* @__PURE__ */ Symbol(void 0);
|
|
16
|
+
var ComputedSignalSymbol = /* @__PURE__ */ Symbol(void 0);
|
|
17
|
+
var ReactiveFlags = {
|
|
18
|
+
IS_REACTIVE: "__v_isReactive",
|
|
19
|
+
IS_READONLY: "__v_isReadonly",
|
|
20
|
+
IS_SHALLOW: "__v_isShallow",
|
|
21
|
+
IS_REF: "__v_isRef",
|
|
22
|
+
RAW: "__v_raw",
|
|
23
|
+
SKIP: "__v_skip"
|
|
24
|
+
};
|
|
25
|
+
var TrackOpTypes = {
|
|
26
|
+
GET: "get",
|
|
27
|
+
HAS: "has",
|
|
28
|
+
ITERATE: "iterate"
|
|
29
|
+
};
|
|
30
|
+
var TriggerOpTypes = {
|
|
31
|
+
SET: "set",
|
|
32
|
+
ADD: "add",
|
|
33
|
+
DELETE: "delete",
|
|
34
|
+
CLEAR: "clear"
|
|
35
|
+
};
|
|
36
|
+
var ITERATE_KEY = /* @__PURE__ */ Symbol("iterate");
|
|
37
|
+
var activeSubscriber = null;
|
|
38
|
+
var isUntracked = false;
|
|
39
|
+
var trackDependency = null;
|
|
40
|
+
var batchDepth = 0;
|
|
41
|
+
var MAX_BATCH_DEPTH = 100;
|
|
42
|
+
var pendingNotifications = /* @__PURE__ */ new Set();
|
|
43
|
+
var pendingTriggerOps = /* @__PURE__ */ new Map();
|
|
44
|
+
var isNotifying = false;
|
|
45
|
+
function signal(initialValue) {
|
|
46
|
+
let value = initialValue;
|
|
47
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
48
|
+
let disposed = false;
|
|
49
|
+
const store = {};
|
|
50
|
+
const SIGNAL_KEY = /* @__PURE__ */ Symbol("signal_value");
|
|
51
|
+
store[SIGNAL_KEY] = initialValue;
|
|
52
|
+
const signalFn = function signalFn2() {
|
|
53
|
+
const currentSubscriber = activeSubscriber;
|
|
54
|
+
if (currentSubscriber && !isUntracked && !disposed) {
|
|
55
|
+
if (!subscribers.has(currentSubscriber)) {
|
|
56
|
+
subscribers.add(currentSubscriber);
|
|
57
|
+
if (trackDependency) {
|
|
58
|
+
trackDependency(signalFn2, () => {
|
|
59
|
+
subscribers.delete(currentSubscriber);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!disposed) {
|
|
65
|
+
track(store, TrackOpTypes.GET, SIGNAL_KEY);
|
|
66
|
+
}
|
|
67
|
+
return value;
|
|
68
|
+
};
|
|
69
|
+
Object.defineProperty(signalFn, SignalSymbol, { value: true });
|
|
70
|
+
signalFn.set = (newValue) => {
|
|
71
|
+
if (disposed) return;
|
|
72
|
+
if (Object.is(newValue, value)) return;
|
|
73
|
+
value = newValue;
|
|
74
|
+
store[SIGNAL_KEY] = newValue;
|
|
75
|
+
notifySubscribers(subscribers, store, SIGNAL_KEY, newValue);
|
|
76
|
+
};
|
|
77
|
+
signalFn.update = (updater) => {
|
|
78
|
+
if (disposed) return;
|
|
79
|
+
const newValue = updater(value);
|
|
80
|
+
if (Object.is(newValue, value)) return;
|
|
81
|
+
value = newValue;
|
|
82
|
+
store[SIGNAL_KEY] = newValue;
|
|
83
|
+
notifySubscribers(subscribers, store, SIGNAL_KEY, newValue);
|
|
84
|
+
};
|
|
85
|
+
signalFn.dispose = () => {
|
|
86
|
+
disposed = true;
|
|
87
|
+
subscribers.clear();
|
|
88
|
+
};
|
|
89
|
+
signalFn.cleanup = () => {
|
|
90
|
+
subscribers.clear();
|
|
91
|
+
trigger(store, TriggerOpTypes.SET, SIGNAL_KEY);
|
|
92
|
+
};
|
|
93
|
+
signalFn._subscribe = (subscriber) => {
|
|
94
|
+
if (disposed) return () => {
|
|
95
|
+
};
|
|
96
|
+
subscribers.add(subscriber);
|
|
97
|
+
return () => subscribers.delete(subscriber);
|
|
98
|
+
};
|
|
99
|
+
return signalFn;
|
|
100
|
+
}
|
|
101
|
+
function createComputedSignalInternal(getter, typeName) {
|
|
102
|
+
let value;
|
|
103
|
+
let dirty = true;
|
|
104
|
+
let isComputing = false;
|
|
105
|
+
const dependencies = /* @__PURE__ */ new Map();
|
|
106
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
107
|
+
let disposed = false;
|
|
108
|
+
const store = {};
|
|
109
|
+
const COMPUTED_SIGNAL_KEY = /* @__PURE__ */ Symbol("computed_signal_value");
|
|
110
|
+
const invalidate = () => {
|
|
111
|
+
if (disposed) return;
|
|
112
|
+
dirty = true;
|
|
113
|
+
trigger(store, TriggerOpTypes.SET, COMPUTED_SIGNAL_KEY);
|
|
114
|
+
const subs = Array.from(subscribers);
|
|
115
|
+
for (const sub of subs) {
|
|
116
|
+
sub();
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const computedFn = function computedFn2() {
|
|
120
|
+
if (disposed) return value;
|
|
121
|
+
track(store, TrackOpTypes.GET, COMPUTED_SIGNAL_KEY);
|
|
122
|
+
if (activeSubscriber && !isUntracked) {
|
|
123
|
+
subscribers.add(activeSubscriber);
|
|
124
|
+
}
|
|
125
|
+
if (dirty) {
|
|
126
|
+
if (isComputing) {
|
|
127
|
+
throw new Error(`[lytjs/signal] Circular dependency detected in ${typeName}.`);
|
|
128
|
+
}
|
|
129
|
+
isComputing = true;
|
|
130
|
+
try {
|
|
131
|
+
for (const unsubscribe of dependencies.values()) {
|
|
132
|
+
unsubscribe();
|
|
133
|
+
}
|
|
134
|
+
dependencies.clear();
|
|
135
|
+
const prevSubscriber = activeSubscriber;
|
|
136
|
+
const prevTrackDependency = trackDependency;
|
|
137
|
+
activeSubscriber = invalidate;
|
|
138
|
+
trackDependency = (dep, unsubscribe) => {
|
|
139
|
+
dependencies.set(dep, unsubscribe);
|
|
140
|
+
};
|
|
141
|
+
try {
|
|
142
|
+
value = getter();
|
|
143
|
+
dirty = false;
|
|
144
|
+
} finally {
|
|
145
|
+
activeSubscriber = prevSubscriber;
|
|
146
|
+
trackDependency = prevTrackDependency;
|
|
147
|
+
}
|
|
148
|
+
} finally {
|
|
149
|
+
isComputing = false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return value;
|
|
153
|
+
};
|
|
154
|
+
Object.defineProperty(computedFn, ComputedSignalSymbol, { value: true });
|
|
155
|
+
const dispose = () => {
|
|
156
|
+
disposed = true;
|
|
157
|
+
for (const unsubscribe of dependencies.values()) {
|
|
158
|
+
unsubscribe();
|
|
159
|
+
}
|
|
160
|
+
dependencies.clear();
|
|
161
|
+
subscribers.clear();
|
|
162
|
+
};
|
|
163
|
+
return { computedFn, invalidate, dispose };
|
|
164
|
+
}
|
|
165
|
+
function computed(fn) {
|
|
166
|
+
const { computedFn, dispose } = createComputedSignalInternal(fn, "computed signal");
|
|
167
|
+
computedFn.dispose = dispose;
|
|
168
|
+
computedFn.stop = dispose;
|
|
169
|
+
return computedFn;
|
|
170
|
+
}
|
|
171
|
+
function writableComputedSignal(getter, setter) {
|
|
172
|
+
const { computedFn, dispose } = createComputedSignalInternal(getter, "writable computed signal");
|
|
173
|
+
computedFn.set = (newValue) => {
|
|
174
|
+
setter(newValue);
|
|
175
|
+
};
|
|
176
|
+
computedFn.dispose = dispose;
|
|
177
|
+
computedFn.stop = dispose;
|
|
178
|
+
return computedFn;
|
|
179
|
+
}
|
|
180
|
+
function signalBatch(fn) {
|
|
181
|
+
if (batchDepth >= MAX_BATCH_DEPTH) {
|
|
182
|
+
fn();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
batchDepth++;
|
|
186
|
+
try {
|
|
187
|
+
fn();
|
|
188
|
+
} finally {
|
|
189
|
+
batchDepth--;
|
|
190
|
+
if (batchDepth === 0) {
|
|
191
|
+
flushPendingNotifications();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function signalUntrack(fn) {
|
|
196
|
+
const prevIsUntracked = isUntracked;
|
|
197
|
+
isUntracked = true;
|
|
198
|
+
try {
|
|
199
|
+
return fn();
|
|
200
|
+
} finally {
|
|
201
|
+
isUntracked = prevIsUntracked;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function _isSignalUntracked() {
|
|
205
|
+
return isUntracked;
|
|
206
|
+
}
|
|
207
|
+
function notifySubscribers(subscribers, store, signalKey, newValue) {
|
|
208
|
+
if (batchDepth > 0 || isNotifying) {
|
|
209
|
+
const it2 = subscribers.values();
|
|
210
|
+
let next2 = it2.next();
|
|
211
|
+
while (!next2.done) {
|
|
212
|
+
pendingNotifications.add(next2.value);
|
|
213
|
+
next2 = it2.next();
|
|
214
|
+
}
|
|
215
|
+
if (store && signalKey !== void 0) {
|
|
216
|
+
pendingTriggerOps.set(signalKey, { store, signalKey, newValue });
|
|
217
|
+
}
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const it = subscribers.values();
|
|
221
|
+
let next = it.next();
|
|
222
|
+
while (!next.done) {
|
|
223
|
+
next.value();
|
|
224
|
+
next = it.next();
|
|
225
|
+
}
|
|
226
|
+
if (store && signalKey !== void 0) {
|
|
227
|
+
trigger(store, TriggerOpTypes.SET, signalKey, newValue);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function flushPendingNotifications() {
|
|
231
|
+
if (isNotifying) return;
|
|
232
|
+
isNotifying = true;
|
|
233
|
+
try {
|
|
234
|
+
let iterations = 0;
|
|
235
|
+
while ((pendingNotifications.size > 0 || pendingTriggerOps.size > 0) && iterations < commonConstants.REACTIVITY_MAX_TRIGGER_DEPTH) {
|
|
236
|
+
const notifications = new Set(pendingNotifications);
|
|
237
|
+
const triggers = new Set(pendingTriggerOps.values());
|
|
238
|
+
pendingNotifications.clear();
|
|
239
|
+
pendingTriggerOps.clear();
|
|
240
|
+
const notifIt = notifications.values();
|
|
241
|
+
let notifNext = notifIt.next();
|
|
242
|
+
while (!notifNext.done) {
|
|
243
|
+
notifNext.value();
|
|
244
|
+
notifNext = notifIt.next();
|
|
245
|
+
}
|
|
246
|
+
const triggerIt = triggers.values();
|
|
247
|
+
let triggerNext = triggerIt.next();
|
|
248
|
+
while (!triggerNext.done) {
|
|
249
|
+
const { store, signalKey, newValue } = triggerNext.value;
|
|
250
|
+
trigger(store, TriggerOpTypes.SET, signalKey, newValue);
|
|
251
|
+
triggerNext = triggerIt.next();
|
|
252
|
+
}
|
|
253
|
+
iterations++;
|
|
254
|
+
}
|
|
255
|
+
} finally {
|
|
256
|
+
isNotifying = false;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function computedSignal(fn) {
|
|
260
|
+
return computed(fn);
|
|
261
|
+
}
|
|
262
|
+
function valueOf(sig) {
|
|
263
|
+
return sig();
|
|
264
|
+
}
|
|
265
|
+
function set(sig, newValue) {
|
|
266
|
+
if (isWritableSignal(sig)) {
|
|
267
|
+
sig.set(newValue);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function isWritableSignal(sig) {
|
|
271
|
+
return typeof sig === "function" && "set" in sig;
|
|
272
|
+
}
|
|
273
|
+
function update(sig, updater) {
|
|
274
|
+
sig.update(updater);
|
|
275
|
+
}
|
|
276
|
+
function readonlySignal(sig) {
|
|
277
|
+
const readonlyFn = function readonlyFn2() {
|
|
278
|
+
return sig();
|
|
279
|
+
};
|
|
280
|
+
Object.defineProperty(readonlyFn, SignalSymbol, { value: true });
|
|
281
|
+
return readonlyFn;
|
|
282
|
+
}
|
|
283
|
+
var activeEffectScope;
|
|
284
|
+
function getActiveEffectScope() {
|
|
285
|
+
return activeEffectScope;
|
|
286
|
+
}
|
|
287
|
+
function effectScope(options) {
|
|
288
|
+
const detached = typeof options === "boolean" ? options : options?.detached;
|
|
289
|
+
const scope = {
|
|
290
|
+
active: true,
|
|
291
|
+
effects: [],
|
|
292
|
+
cleanups: [],
|
|
293
|
+
parent: activeEffectScope,
|
|
294
|
+
detached: !!detached,
|
|
295
|
+
run(fn) {
|
|
296
|
+
if (!this.active) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const prevScope = activeEffectScope;
|
|
300
|
+
activeEffectScope = this;
|
|
301
|
+
try {
|
|
302
|
+
return fn();
|
|
303
|
+
} finally {
|
|
304
|
+
activeEffectScope = prevScope;
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
stop() {
|
|
308
|
+
if (!this.active) return;
|
|
309
|
+
this.active = false;
|
|
310
|
+
for (const effect2 of this.effects) {
|
|
311
|
+
try {
|
|
312
|
+
effect2.stop();
|
|
313
|
+
} catch (e) {
|
|
314
|
+
commonError.error(`Error stopping effect in scope: ${String(e)}`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
for (const cleanup of this.cleanups) {
|
|
318
|
+
try {
|
|
319
|
+
cleanup();
|
|
320
|
+
} catch (e) {
|
|
321
|
+
commonError.error(`Error running cleanup in scope: ${String(e)}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (this.parent) {
|
|
325
|
+
const idx = this.parent.effects.indexOf(commonAssertions.unsafeCast(this));
|
|
326
|
+
if (idx !== -1) {
|
|
327
|
+
this.parent.effects.splice(idx, 1);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
this.effects.length = 0;
|
|
331
|
+
this.cleanups.length = 0;
|
|
332
|
+
this.parent = void 0;
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
if (!scope.detached && activeEffectScope) {
|
|
336
|
+
activeEffectScope.effects.push(commonAssertions.unsafeCast(scope));
|
|
337
|
+
}
|
|
338
|
+
return scope;
|
|
339
|
+
}
|
|
340
|
+
function getCurrentScope() {
|
|
341
|
+
return activeEffectScope;
|
|
342
|
+
}
|
|
343
|
+
function onScopeDispose(fn) {
|
|
344
|
+
if (activeEffectScope) {
|
|
345
|
+
activeEffectScope.cleanups.push(fn);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
var activeEffect;
|
|
349
|
+
var _trackDepth = 0;
|
|
350
|
+
var targetMap = /* @__PURE__ */ new WeakMap();
|
|
351
|
+
var shouldTrack = true;
|
|
352
|
+
var trackStack = [];
|
|
353
|
+
var isFirstRenderPass = false;
|
|
354
|
+
var skippedTrackingCount = 0;
|
|
355
|
+
function withFirstRenderOptimization(fn) {
|
|
356
|
+
const wasFirstRender = isFirstRenderPass;
|
|
357
|
+
isFirstRenderPass = true;
|
|
358
|
+
try {
|
|
359
|
+
return fn();
|
|
360
|
+
} finally {
|
|
361
|
+
if (!wasFirstRender) {
|
|
362
|
+
isFirstRenderPass = false;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
function shouldSkipTracking() {
|
|
367
|
+
return isFirstRenderPass;
|
|
368
|
+
}
|
|
369
|
+
function getSkippedTrackingCount() {
|
|
370
|
+
return skippedTrackingCount;
|
|
371
|
+
}
|
|
372
|
+
function resetSkippedTrackingCount() {
|
|
373
|
+
skippedTrackingCount = 0;
|
|
374
|
+
}
|
|
375
|
+
function getActiveEffect() {
|
|
376
|
+
return activeEffect;
|
|
377
|
+
}
|
|
378
|
+
function getShouldTrack() {
|
|
379
|
+
return shouldTrack;
|
|
380
|
+
}
|
|
381
|
+
var createDep = () => {
|
|
382
|
+
return /* @__PURE__ */ new Set();
|
|
383
|
+
};
|
|
384
|
+
var triggerDepth = 0;
|
|
385
|
+
function track(target, _type, key) {
|
|
386
|
+
if (!shouldTrack || activeEffect === void 0) return;
|
|
387
|
+
if (_isSignalUntracked()) return;
|
|
388
|
+
let depsMap = targetMap.get(target);
|
|
389
|
+
if (!depsMap) {
|
|
390
|
+
targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
|
|
391
|
+
}
|
|
392
|
+
let dep = depsMap.get(key);
|
|
393
|
+
if (!dep) {
|
|
394
|
+
depsMap.set(key, dep = createDep());
|
|
395
|
+
}
|
|
396
|
+
trackEffect(dep);
|
|
397
|
+
}
|
|
398
|
+
function trackEffect(dep) {
|
|
399
|
+
if (shouldSkipTracking()) {
|
|
400
|
+
skippedTrackingCount++;
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (activeEffect && !dep.has(activeEffect)) {
|
|
404
|
+
dep.add(activeEffect);
|
|
405
|
+
activeEffect.deps.push(dep);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function trigger(target, type, key, newValue, oldValue) {
|
|
409
|
+
const depsMap = targetMap.get(target);
|
|
410
|
+
if (!depsMap) return;
|
|
411
|
+
const deps = [];
|
|
412
|
+
if (type === "clear") {
|
|
413
|
+
deps.push(...depsMap.values());
|
|
414
|
+
} else {
|
|
415
|
+
if (key !== void 0) {
|
|
416
|
+
deps.push(depsMap.get(key));
|
|
417
|
+
}
|
|
418
|
+
if (type === "add") {
|
|
419
|
+
if (Array.isArray(target)) {
|
|
420
|
+
deps.push(depsMap.get("length"));
|
|
421
|
+
} else {
|
|
422
|
+
deps.push(depsMap.get(ITERATE_KEY));
|
|
423
|
+
}
|
|
424
|
+
} else if (type === "delete") {
|
|
425
|
+
if (!Array.isArray(target)) {
|
|
426
|
+
deps.push(depsMap.get(ITERATE_KEY));
|
|
427
|
+
}
|
|
428
|
+
} else if (type === "set") {
|
|
429
|
+
if (Array.isArray(target) && isIntegerKey(key)) {
|
|
430
|
+
deps.push(depsMap.get("length"));
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
const effects = [];
|
|
435
|
+
for (const dep of deps) {
|
|
436
|
+
if (dep) {
|
|
437
|
+
for (const effect2 of dep) {
|
|
438
|
+
effects.push(effect2);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
triggerEffects([...new Set(effects)], target, type, key, newValue, oldValue);
|
|
443
|
+
}
|
|
444
|
+
function triggerEffects(effects, target, type, key, newValue, oldValue) {
|
|
445
|
+
if (triggerDepth > commonConstants.REACTIVITY_MAX_TRIGGER_DEPTH) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
triggerDepth++;
|
|
449
|
+
try {
|
|
450
|
+
for (const effect2 of effects) {
|
|
451
|
+
if (effect2.computed) {
|
|
452
|
+
triggerEffect(effect2, target, type, key, newValue, oldValue);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
for (const effect2 of effects) {
|
|
456
|
+
if (!effect2.computed) {
|
|
457
|
+
triggerEffect(effect2, target, type, key, newValue, oldValue);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
} finally {
|
|
461
|
+
triggerDepth--;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
function triggerEffect(effect2, target, type, key, newValue, oldValue) {
|
|
465
|
+
if (effect2 !== activeEffect || effect2.allowRecurse) {
|
|
466
|
+
if (effect2.scheduler) {
|
|
467
|
+
effect2.scheduler();
|
|
468
|
+
} else {
|
|
469
|
+
effect2.run();
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
var ReactiveEffect = class {
|
|
474
|
+
constructor(fn, scheduler) {
|
|
475
|
+
this.fn = fn;
|
|
476
|
+
this.scheduler = scheduler;
|
|
477
|
+
this.active = true;
|
|
478
|
+
this.deps = [];
|
|
479
|
+
this.parent = void 0;
|
|
480
|
+
// 运行前清理(onEffectCleanup 注册的)
|
|
481
|
+
this._cleanups = [];
|
|
482
|
+
const scope = getActiveEffectScope();
|
|
483
|
+
if (scope && scope.active) {
|
|
484
|
+
scope.effects.push(this);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
run() {
|
|
488
|
+
if (!this.active) {
|
|
489
|
+
return void 0;
|
|
490
|
+
}
|
|
491
|
+
if (this._cleanups.length > 0) {
|
|
492
|
+
for (let i = 0; i < this._cleanups.length; i++) {
|
|
493
|
+
this._cleanups[i]();
|
|
494
|
+
}
|
|
495
|
+
this._cleanups.length = 0;
|
|
496
|
+
}
|
|
497
|
+
const prevShouldTrack = shouldTrack;
|
|
498
|
+
try {
|
|
499
|
+
this.parent = activeEffect;
|
|
500
|
+
activeEffect = this;
|
|
501
|
+
shouldTrack = true;
|
|
502
|
+
_trackDepth++;
|
|
503
|
+
return this.fn();
|
|
504
|
+
} catch (error3) {
|
|
505
|
+
if (this.onError) {
|
|
506
|
+
this.onError(error3);
|
|
507
|
+
return void 0;
|
|
508
|
+
}
|
|
509
|
+
throw error3;
|
|
510
|
+
} finally {
|
|
511
|
+
_trackDepth--;
|
|
512
|
+
activeEffect = this.parent;
|
|
513
|
+
shouldTrack = prevShouldTrack;
|
|
514
|
+
this.parent = void 0;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
stop() {
|
|
518
|
+
if (this.active) {
|
|
519
|
+
cleanupEffect(this);
|
|
520
|
+
if (this._cleanups.length > 0) {
|
|
521
|
+
for (let i = 0; i < this._cleanups.length; i++) {
|
|
522
|
+
this._cleanups[i]();
|
|
523
|
+
}
|
|
524
|
+
this._cleanups.length = 0;
|
|
525
|
+
}
|
|
526
|
+
if (this.onStop) {
|
|
527
|
+
this.onStop();
|
|
528
|
+
}
|
|
529
|
+
this.active = false;
|
|
530
|
+
this.scheduler = void 0;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
function cleanupEffect(effect2) {
|
|
535
|
+
const { deps } = effect2;
|
|
536
|
+
for (let i = 0; i < deps.length; i++) {
|
|
537
|
+
deps[i].delete(effect2);
|
|
538
|
+
}
|
|
539
|
+
deps.length = 0;
|
|
540
|
+
}
|
|
541
|
+
function effect(fn, options) {
|
|
542
|
+
const _effect = new ReactiveEffect(fn);
|
|
543
|
+
if (options) {
|
|
544
|
+
_effect.scheduler = options.scheduler;
|
|
545
|
+
_effect.allowRecurse = options.allowRecurse;
|
|
546
|
+
_effect.onStop = options.onStop;
|
|
547
|
+
_effect.onTrack = options.onTrack;
|
|
548
|
+
_effect.onTrigger = options.onTrigger;
|
|
549
|
+
_effect.onError = options.onError;
|
|
550
|
+
}
|
|
551
|
+
if (!options || !options.lazy) {
|
|
552
|
+
_effect.run();
|
|
553
|
+
}
|
|
554
|
+
const runner = _effect.run.bind(_effect);
|
|
555
|
+
runner.effect = _effect;
|
|
556
|
+
return runner;
|
|
557
|
+
}
|
|
558
|
+
function stop(runner) {
|
|
559
|
+
runner.effect.stop();
|
|
560
|
+
}
|
|
561
|
+
function pauseTracking() {
|
|
562
|
+
trackStack.push(shouldTrack);
|
|
563
|
+
shouldTrack = false;
|
|
564
|
+
}
|
|
565
|
+
function enableTracking() {
|
|
566
|
+
trackStack.push(shouldTrack);
|
|
567
|
+
shouldTrack = true;
|
|
568
|
+
}
|
|
569
|
+
function resetTracking() {
|
|
570
|
+
const last = trackStack.pop();
|
|
571
|
+
shouldTrack = last === void 0 ? true : last;
|
|
572
|
+
}
|
|
573
|
+
function batch(fn) {
|
|
574
|
+
const stackLength = trackStack.length;
|
|
575
|
+
pauseTracking();
|
|
576
|
+
try {
|
|
577
|
+
fn();
|
|
578
|
+
} finally {
|
|
579
|
+
while (trackStack.length > stackLength) {
|
|
580
|
+
trackStack.pop();
|
|
581
|
+
}
|
|
582
|
+
shouldTrack = trackStack.length > 0 ? trackStack[trackStack.length - 1] : true;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
function batchAsync(fn) {
|
|
586
|
+
const stackLength = trackStack.length;
|
|
587
|
+
pauseTracking();
|
|
588
|
+
const restoreTracking = () => {
|
|
589
|
+
while (trackStack.length > stackLength) {
|
|
590
|
+
trackStack.pop();
|
|
591
|
+
}
|
|
592
|
+
shouldTrack = trackStack.length > 0 ? trackStack[trackStack.length - 1] : true;
|
|
593
|
+
};
|
|
594
|
+
try {
|
|
595
|
+
const result = fn();
|
|
596
|
+
if (result && typeof result === "object" && "then" in result) {
|
|
597
|
+
return result.finally(restoreTracking);
|
|
598
|
+
}
|
|
599
|
+
restoreTracking();
|
|
600
|
+
return Promise.resolve();
|
|
601
|
+
} catch (e) {
|
|
602
|
+
restoreTracking();
|
|
603
|
+
return Promise.reject(e);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
function untrack(fn) {
|
|
607
|
+
const stackLength = trackStack.length;
|
|
608
|
+
pauseTracking();
|
|
609
|
+
try {
|
|
610
|
+
return fn();
|
|
611
|
+
} finally {
|
|
612
|
+
while (trackStack.length > stackLength) {
|
|
613
|
+
trackStack.pop();
|
|
614
|
+
}
|
|
615
|
+
shouldTrack = trackStack.length > 0 ? trackStack[trackStack.length - 1] : true;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
function onEffectCleanup(fn, failSilently = false) {
|
|
619
|
+
if (activeEffect === void 0) {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
activeEffect._cleanups.push(fn);
|
|
623
|
+
}
|
|
624
|
+
function isIntegerKey(key) {
|
|
625
|
+
return typeof key === "string" && key !== "NaN" && key[0] !== "-" && "" + parseInt(key, 10) === key && Number.isSafeInteger(Number(key));
|
|
626
|
+
}
|
|
627
|
+
var MAX_RAW_DEPTH = 100;
|
|
628
|
+
var _rawSeenSet = /* @__PURE__ */ new Set();
|
|
629
|
+
var _rawDepth = 0;
|
|
630
|
+
function toRaw(observed) {
|
|
631
|
+
_rawDepth++;
|
|
632
|
+
if (_rawDepth === 1) {
|
|
633
|
+
_rawSeenSet.clear();
|
|
634
|
+
}
|
|
635
|
+
try {
|
|
636
|
+
let current = observed;
|
|
637
|
+
let depth = 0;
|
|
638
|
+
while (current && current[ReactiveFlags.RAW]) {
|
|
639
|
+
if (_rawSeenSet.has(current) || depth >= MAX_RAW_DEPTH) return current;
|
|
640
|
+
_rawSeenSet.add(current);
|
|
641
|
+
current = current[ReactiveFlags.RAW];
|
|
642
|
+
depth++;
|
|
643
|
+
}
|
|
644
|
+
return current;
|
|
645
|
+
} finally {
|
|
646
|
+
_rawDepth--;
|
|
647
|
+
if (_rawDepth === 0) {
|
|
648
|
+
_rawSeenSet.clear();
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
function isRef(r) {
|
|
653
|
+
return !!(r && typeof r === "object" && r.__v_isRef === true);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// src/reactive.ts
|
|
657
|
+
var MUTATING_METHODS = /* @__PURE__ */ new Set(["set", "add", "delete", "clear"]);
|
|
658
|
+
var collectionMethodCache = /* @__PURE__ */ new WeakMap();
|
|
659
|
+
var arrayInstrumentations = {};
|
|
660
|
+
["includes", "indexOf", "lastIndexOf"].forEach((method) => {
|
|
661
|
+
const originMethod = Array.prototype[method];
|
|
662
|
+
arrayInstrumentations[method] = function(...args) {
|
|
663
|
+
const arr = toRaw(this);
|
|
664
|
+
track(arr, TrackOpTypes.HAS, "length");
|
|
665
|
+
const result = originMethod.apply(arr, args);
|
|
666
|
+
if (result === -1 || result === false) {
|
|
667
|
+
return originMethod.apply(
|
|
668
|
+
arr,
|
|
669
|
+
args.map((a) => toRaw(a))
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
return result;
|
|
673
|
+
};
|
|
674
|
+
});
|
|
675
|
+
["push", "pop", "shift", "unshift", "splice"].forEach((method) => {
|
|
676
|
+
const originMethod = Array.prototype[method];
|
|
677
|
+
arrayInstrumentations[method] = function(...args) {
|
|
678
|
+
pauseTracking();
|
|
679
|
+
try {
|
|
680
|
+
const result = originMethod.apply(this, args);
|
|
681
|
+
return result;
|
|
682
|
+
} finally {
|
|
683
|
+
resetTracking();
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
});
|
|
687
|
+
["sort", "reverse", "fill", "copyWithin"].forEach((method) => {
|
|
688
|
+
const originMethod = Array.prototype[method];
|
|
689
|
+
arrayInstrumentations[method] = function(...args) {
|
|
690
|
+
const arr = toRaw(this);
|
|
691
|
+
pauseTracking();
|
|
692
|
+
try {
|
|
693
|
+
const result = originMethod.apply(arr, args);
|
|
694
|
+
trigger(arr, TriggerOpTypes.SET, "length");
|
|
695
|
+
return result;
|
|
696
|
+
} finally {
|
|
697
|
+
resetTracking();
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
});
|
|
701
|
+
var builtInSymbols = new Set(
|
|
702
|
+
Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => {
|
|
703
|
+
const value = commonAssertions.unsafeCast(Symbol[key]);
|
|
704
|
+
return commonIs.isSymbol(value) ? value : void 0;
|
|
705
|
+
}).filter((sym) => sym !== void 0)
|
|
706
|
+
);
|
|
707
|
+
function isNonTrackableKey(key) {
|
|
708
|
+
return key === "__proto__" || key === "__v_isRef";
|
|
709
|
+
}
|
|
710
|
+
function toTriggerKey(value) {
|
|
711
|
+
if (typeof value === "string" || typeof value === "symbol") {
|
|
712
|
+
return value;
|
|
713
|
+
}
|
|
714
|
+
return void 0;
|
|
715
|
+
}
|
|
716
|
+
function createReactiveObject(target, isReadonlyFlag, _isShallow, baseHandlers, collectionHandlers, proxyMap) {
|
|
717
|
+
if (!commonIs.isObject(target)) {
|
|
718
|
+
return target;
|
|
719
|
+
}
|
|
720
|
+
if (target[ReactiveFlags.SKIP]) {
|
|
721
|
+
return target;
|
|
722
|
+
}
|
|
723
|
+
if (target[ReactiveFlags.RAW] && !(isReadonlyFlag && target[ReactiveFlags.IS_REACTIVE])) {
|
|
724
|
+
return target;
|
|
725
|
+
}
|
|
726
|
+
const existingProxy = proxyMap.get(target);
|
|
727
|
+
if (existingProxy) {
|
|
728
|
+
return existingProxy;
|
|
729
|
+
}
|
|
730
|
+
const handlers = commonIs.isMap(target) || commonIs.isSet(target) ? collectionHandlers : baseHandlers;
|
|
731
|
+
const proxy = new Proxy(target, handlers);
|
|
732
|
+
proxyMap.set(target, proxy);
|
|
733
|
+
return proxy;
|
|
734
|
+
}
|
|
735
|
+
function createMutableHandler(isReadonly2, isShallow) {
|
|
736
|
+
return {
|
|
737
|
+
get(target, key, _receiver) {
|
|
738
|
+
if (key === ReactiveFlags.IS_REACTIVE) return !isReadonly2;
|
|
739
|
+
if (key === ReactiveFlags.IS_READONLY) return isReadonly2;
|
|
740
|
+
if (key === ReactiveFlags.IS_SHALLOW) return isShallow;
|
|
741
|
+
if (key === ReactiveFlags.RAW) return target;
|
|
742
|
+
const targetIsArray = Array.isArray(target);
|
|
743
|
+
if (!isReadonly2 && targetIsArray && commonIs.hasOwn(arrayInstrumentations, key)) {
|
|
744
|
+
return Reflect.get(arrayInstrumentations, key, _receiver);
|
|
745
|
+
}
|
|
746
|
+
const res = Reflect.get(target, key, _receiver);
|
|
747
|
+
if (commonIs.isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKey(key)) {
|
|
748
|
+
return res;
|
|
749
|
+
}
|
|
750
|
+
if (!isReadonly2) {
|
|
751
|
+
track(target, TrackOpTypes.GET, key);
|
|
752
|
+
}
|
|
753
|
+
if (isShallow) {
|
|
754
|
+
return res;
|
|
755
|
+
}
|
|
756
|
+
if (isRef(res)) {
|
|
757
|
+
return targetIsArray && isIntegerKey(key) ? res : res.value;
|
|
758
|
+
}
|
|
759
|
+
if (commonIs.isObject(res)) {
|
|
760
|
+
return isReadonly2 ? readonly(res) : reactive(res);
|
|
761
|
+
}
|
|
762
|
+
return res;
|
|
763
|
+
},
|
|
764
|
+
set(target, key, value, receiver) {
|
|
765
|
+
if (isReadonly2) {
|
|
766
|
+
return true;
|
|
767
|
+
}
|
|
768
|
+
let oldValue = Reflect.get(target, key);
|
|
769
|
+
if (!isShallow) {
|
|
770
|
+
value = toRaw(value);
|
|
771
|
+
oldValue = toRaw(oldValue);
|
|
772
|
+
if (!Array.isArray(target) && isRef(oldValue) && !isRef(value)) {
|
|
773
|
+
oldValue.value = value;
|
|
774
|
+
return true;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
const hadKey = Array.isArray(target) && isIntegerKey(key) ? Number(key) < target.length : commonIs.hasOwn(target, key);
|
|
778
|
+
const result = Reflect.set(target, key, value, receiver);
|
|
779
|
+
if (target === toRaw(receiver)) {
|
|
780
|
+
if (!hadKey) {
|
|
781
|
+
trigger(target, TriggerOpTypes.ADD, key, value);
|
|
782
|
+
} else if (commonIs.hasChanged(value, oldValue)) {
|
|
783
|
+
trigger(target, TriggerOpTypes.SET, key, value, oldValue);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
return result;
|
|
787
|
+
},
|
|
788
|
+
deleteProperty(target, key) {
|
|
789
|
+
if (isReadonly2) {
|
|
790
|
+
return true;
|
|
791
|
+
}
|
|
792
|
+
const hadKey = commonIs.hasOwn(target, key);
|
|
793
|
+
const oldValue = Reflect.get(target, key);
|
|
794
|
+
const result = Reflect.deleteProperty(target, key);
|
|
795
|
+
if (result && hadKey) {
|
|
796
|
+
trigger(target, TriggerOpTypes.DELETE, key, void 0, oldValue);
|
|
797
|
+
}
|
|
798
|
+
return result;
|
|
799
|
+
},
|
|
800
|
+
has(target, key) {
|
|
801
|
+
const result = Reflect.has(target, key);
|
|
802
|
+
if (!commonIs.isSymbol(key) || !builtInSymbols.has(key)) {
|
|
803
|
+
if (!isReadonly2) {
|
|
804
|
+
track(target, TrackOpTypes.HAS, key);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
return result;
|
|
808
|
+
},
|
|
809
|
+
// FIX: P2-08 ownKeys 属性枚举顺序一致:
|
|
810
|
+
// 返回 Reflect.ownKeys 结果,确保与原生 Object.keys() 枚举顺序一致
|
|
811
|
+
ownKeys(target) {
|
|
812
|
+
if (!isReadonly2) {
|
|
813
|
+
track(target, TrackOpTypes.ITERATE, Array.isArray(target) ? "length" : ITERATE_KEY);
|
|
814
|
+
}
|
|
815
|
+
return Reflect.ownKeys(target);
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
function createCollectionHandler(isReadonly2, isShallow) {
|
|
820
|
+
return {
|
|
821
|
+
get(target, key, _receiver) {
|
|
822
|
+
if (key === ReactiveFlags.IS_REACTIVE) return !isReadonly2;
|
|
823
|
+
if (key === ReactiveFlags.IS_READONLY) return isReadonly2;
|
|
824
|
+
if (key === ReactiveFlags.IS_SHALLOW) return isShallow;
|
|
825
|
+
if (key === ReactiveFlags.RAW) return target;
|
|
826
|
+
if (key === "size" || key === "has" || key === "forEach" || key === "entries" || key === "keys" || key === "values" || key === Symbol.iterator) {
|
|
827
|
+
track(target, TrackOpTypes.GET, ITERATE_KEY);
|
|
828
|
+
}
|
|
829
|
+
const res = Reflect.get(target, key, target);
|
|
830
|
+
if (typeof res === "function") {
|
|
831
|
+
if (!isReadonly2 && (key === "entries" || key === "keys" || key === "values" || key === Symbol.iterator)) {
|
|
832
|
+
let methodCache = collectionMethodCache.get(target);
|
|
833
|
+
if (!methodCache) {
|
|
834
|
+
methodCache = /* @__PURE__ */ new Map();
|
|
835
|
+
collectionMethodCache.set(target, methodCache);
|
|
836
|
+
}
|
|
837
|
+
let cachedFn = methodCache.get(key);
|
|
838
|
+
if (!cachedFn) {
|
|
839
|
+
cachedFn = (...args) => {
|
|
840
|
+
track(target, TrackOpTypes.GET, ITERATE_KEY);
|
|
841
|
+
return res.apply(target, args);
|
|
842
|
+
};
|
|
843
|
+
methodCache.set(key, cachedFn);
|
|
844
|
+
}
|
|
845
|
+
return cachedFn;
|
|
846
|
+
}
|
|
847
|
+
if (!isReadonly2) {
|
|
848
|
+
if (MUTATING_METHODS.has(key)) {
|
|
849
|
+
return (...args) => {
|
|
850
|
+
const rawTarget = toRaw(target);
|
|
851
|
+
if (key === "set") {
|
|
852
|
+
const oldValue = rawTarget.get(args[0]);
|
|
853
|
+
const hadKey = rawTarget.has(args[0]);
|
|
854
|
+
const result2 = res.apply(target, args);
|
|
855
|
+
if (!hadKey || !Object.is(toRaw(oldValue), toRaw(args[1]))) {
|
|
856
|
+
const triggerKey = toTriggerKey(args[0]);
|
|
857
|
+
if (triggerKey !== void 0) {
|
|
858
|
+
trigger(target, TriggerOpTypes.SET, triggerKey, args[1], oldValue);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
return result2;
|
|
862
|
+
} else if (key === "add") {
|
|
863
|
+
const had = rawTarget.has(args[0]);
|
|
864
|
+
const result2 = res.apply(target, args);
|
|
865
|
+
if (!had) {
|
|
866
|
+
const triggerKey = toTriggerKey(args[0]);
|
|
867
|
+
if (triggerKey !== void 0) {
|
|
868
|
+
trigger(target, TriggerOpTypes.ADD, triggerKey, args[0]);
|
|
869
|
+
}
|
|
870
|
+
trigger(target, TriggerOpTypes.ADD, ITERATE_KEY);
|
|
871
|
+
}
|
|
872
|
+
return result2;
|
|
873
|
+
} else if (key === "delete") {
|
|
874
|
+
const hadKey = rawTarget.has(args[0]);
|
|
875
|
+
const result2 = res.apply(target, args);
|
|
876
|
+
if (hadKey) {
|
|
877
|
+
const triggerKey = toTriggerKey(args[0]);
|
|
878
|
+
if (triggerKey !== void 0) {
|
|
879
|
+
trigger(target, TriggerOpTypes.DELETE, triggerKey, void 0, void 0);
|
|
880
|
+
}
|
|
881
|
+
trigger(target, TriggerOpTypes.DELETE, ITERATE_KEY);
|
|
882
|
+
}
|
|
883
|
+
return result2;
|
|
884
|
+
} else if (key === "clear") {
|
|
885
|
+
const hadItems = rawTarget.size > 0;
|
|
886
|
+
const result2 = res.apply(target, args);
|
|
887
|
+
if (hadItems) {
|
|
888
|
+
trigger(target, TriggerOpTypes.CLEAR, void 0, void 0, void 0);
|
|
889
|
+
}
|
|
890
|
+
return result2;
|
|
891
|
+
}
|
|
892
|
+
const result = res.apply(target, args);
|
|
893
|
+
trigger(target, TriggerOpTypes.ADD, ITERATE_KEY);
|
|
894
|
+
return result;
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
if (key === "get") {
|
|
898
|
+
return (...args) => {
|
|
899
|
+
track(target, TrackOpTypes.GET, args[0]);
|
|
900
|
+
return res.apply(target, args);
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
} else {
|
|
904
|
+
if (MUTATING_METHODS.has(key)) {
|
|
905
|
+
return (..._args) => {
|
|
906
|
+
if (key === "delete") return false;
|
|
907
|
+
return void 0;
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
return res.bind(target);
|
|
912
|
+
}
|
|
913
|
+
return res;
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
var mutableHandlers = createMutableHandler(false, false);
|
|
918
|
+
var readonlyHandlers = createMutableHandler(true, false);
|
|
919
|
+
var shallowReactiveHandlers = createMutableHandler(false, true);
|
|
920
|
+
var shallowReadonlyHandlers = createMutableHandler(true, true);
|
|
921
|
+
var mutableCollectionHandlers = createCollectionHandler(false, false);
|
|
922
|
+
var readonlyCollectionHandlers = createCollectionHandler(true, false);
|
|
923
|
+
var shallowCollectionHandlers = createCollectionHandler(false, true);
|
|
924
|
+
var shallowReadonlyCollectionHandlers = createCollectionHandler(true, true);
|
|
925
|
+
var reactiveMap = /* @__PURE__ */ new WeakMap();
|
|
926
|
+
var shallowReactiveMap = /* @__PURE__ */ new WeakMap();
|
|
927
|
+
var readonlyMap = /* @__PURE__ */ new WeakMap();
|
|
928
|
+
var shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
|
|
929
|
+
function reactive(target) {
|
|
930
|
+
if (isReadonly(target)) return target;
|
|
931
|
+
return createReactiveObject(
|
|
932
|
+
target,
|
|
933
|
+
false,
|
|
934
|
+
false,
|
|
935
|
+
mutableHandlers,
|
|
936
|
+
mutableCollectionHandlers,
|
|
937
|
+
reactiveMap
|
|
938
|
+
);
|
|
939
|
+
}
|
|
940
|
+
function shallowReactive(target) {
|
|
941
|
+
return createReactiveObject(
|
|
942
|
+
target,
|
|
943
|
+
false,
|
|
944
|
+
true,
|
|
945
|
+
shallowReactiveHandlers,
|
|
946
|
+
shallowCollectionHandlers,
|
|
947
|
+
shallowReactiveMap
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
function readonly(target) {
|
|
951
|
+
return createReactiveObject(
|
|
952
|
+
target,
|
|
953
|
+
true,
|
|
954
|
+
false,
|
|
955
|
+
readonlyHandlers,
|
|
956
|
+
readonlyCollectionHandlers,
|
|
957
|
+
readonlyMap
|
|
958
|
+
);
|
|
959
|
+
}
|
|
960
|
+
function shallowReadonly(target) {
|
|
961
|
+
return createReactiveObject(
|
|
962
|
+
target,
|
|
963
|
+
true,
|
|
964
|
+
true,
|
|
965
|
+
shallowReadonlyHandlers,
|
|
966
|
+
shallowReadonlyCollectionHandlers,
|
|
967
|
+
shallowReadonlyMap
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
function isReactive(value) {
|
|
971
|
+
if (isReadonly(value)) {
|
|
972
|
+
return isReactive(value[ReactiveFlags.RAW]);
|
|
973
|
+
}
|
|
974
|
+
return !!(value && value[ReactiveFlags.IS_REACTIVE]);
|
|
975
|
+
}
|
|
976
|
+
function isReadonly(value) {
|
|
977
|
+
return !!(value && value[ReactiveFlags.IS_READONLY]);
|
|
978
|
+
}
|
|
979
|
+
function isProxy(value) {
|
|
980
|
+
return isReactive(value) || isReadonly(value);
|
|
981
|
+
}
|
|
982
|
+
function markRaw(value) {
|
|
983
|
+
if (Object.isFrozen(value) || Object.isSealed(value)) {
|
|
984
|
+
return value;
|
|
985
|
+
}
|
|
986
|
+
Object.defineProperty(value, ReactiveFlags.SKIP, { value: true });
|
|
987
|
+
return value;
|
|
988
|
+
}
|
|
989
|
+
var RefImpl = class {
|
|
990
|
+
constructor(value, isShallow) {
|
|
991
|
+
// 使用 Dep 类型替代 Set<any>,提供更精确的类型约束
|
|
992
|
+
this.dep = createDep();
|
|
993
|
+
this.__v_isRef = true;
|
|
994
|
+
this.__v_isShallow = isShallow || void 0;
|
|
995
|
+
this._rawValue = isShallow ? value : toRaw(value);
|
|
996
|
+
this._value = isShallow ? value : toReactive(value);
|
|
997
|
+
}
|
|
998
|
+
get value() {
|
|
999
|
+
trackRefValue(this);
|
|
1000
|
+
return this._value;
|
|
1001
|
+
}
|
|
1002
|
+
set value(newVal) {
|
|
1003
|
+
const useDirectValue = this.__v_isShallow;
|
|
1004
|
+
newVal = useDirectValue ? newVal : toRaw(newVal);
|
|
1005
|
+
if (commonIs.hasChanged(newVal, this._rawValue)) {
|
|
1006
|
+
const oldVal = this._rawValue;
|
|
1007
|
+
this._rawValue = newVal;
|
|
1008
|
+
this._value = useDirectValue ? newVal : toReactive(newVal);
|
|
1009
|
+
triggerRefValue(this, newVal, oldVal);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
var ShallowRefImpl = class {
|
|
1014
|
+
constructor(value) {
|
|
1015
|
+
// 使用 Dep 类型替代 Set<any>,提供更精确的类型约束
|
|
1016
|
+
this.dep = createDep();
|
|
1017
|
+
this.__v_isRef = true;
|
|
1018
|
+
this.__v_isShallow = true;
|
|
1019
|
+
this._rawValue = value;
|
|
1020
|
+
this._value = value;
|
|
1021
|
+
}
|
|
1022
|
+
get value() {
|
|
1023
|
+
trackRefValue(this);
|
|
1024
|
+
return this._value;
|
|
1025
|
+
}
|
|
1026
|
+
set value(newVal) {
|
|
1027
|
+
if (commonIs.hasChanged(newVal, this._rawValue)) {
|
|
1028
|
+
const oldVal = this._rawValue;
|
|
1029
|
+
this._rawValue = newVal;
|
|
1030
|
+
this._value = newVal;
|
|
1031
|
+
triggerRefValue(this, newVal, oldVal);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
function trackRefValue(ref2) {
|
|
1036
|
+
if (getShouldTrack() && getActiveEffect()) {
|
|
1037
|
+
track(ref2, TrackOpTypes.GET, "value");
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
function triggerRefValue(ref2, newVal, oldVal) {
|
|
1041
|
+
trigger(ref2, TriggerOpTypes.SET, "value", newVal, oldVal);
|
|
1042
|
+
}
|
|
1043
|
+
function ref(value) {
|
|
1044
|
+
if (isRef(value)) {
|
|
1045
|
+
return value;
|
|
1046
|
+
}
|
|
1047
|
+
return commonAssertions.unsafeCast(new RefImpl(value, false));
|
|
1048
|
+
}
|
|
1049
|
+
function shallowRef(value) {
|
|
1050
|
+
if (isRef(value)) return commonAssertions.unsafeCast(value);
|
|
1051
|
+
return commonAssertions.unsafeCast(new ShallowRefImpl(value));
|
|
1052
|
+
}
|
|
1053
|
+
function triggerRef(ref2) {
|
|
1054
|
+
triggerRefValue(commonAssertions.unsafeCast(ref2), ref2.value);
|
|
1055
|
+
}
|
|
1056
|
+
function isShallowRef(r) {
|
|
1057
|
+
return isRef(r) && !!r.__v_isShallow;
|
|
1058
|
+
}
|
|
1059
|
+
function isComputedRef(r) {
|
|
1060
|
+
return isRef(r) && !!r.__v_isComputed;
|
|
1061
|
+
}
|
|
1062
|
+
function unref(r) {
|
|
1063
|
+
return isRef(r) ? r.value : r;
|
|
1064
|
+
}
|
|
1065
|
+
function toRef(object, key) {
|
|
1066
|
+
if (isRef(object[key])) return commonAssertions.unsafeCast(object[key]);
|
|
1067
|
+
return commonAssertions.unsafeCast(new ObjectRefImpl(object, key));
|
|
1068
|
+
}
|
|
1069
|
+
function toRefs(object) {
|
|
1070
|
+
const result = {};
|
|
1071
|
+
for (const key in object) {
|
|
1072
|
+
result[key] = toRef(object, key);
|
|
1073
|
+
}
|
|
1074
|
+
return result;
|
|
1075
|
+
}
|
|
1076
|
+
function customRef(factory) {
|
|
1077
|
+
return commonAssertions.unsafeCast(new CustomRefImpl(factory));
|
|
1078
|
+
}
|
|
1079
|
+
function toValue(source) {
|
|
1080
|
+
if (isRef(source)) return source.value;
|
|
1081
|
+
if (typeof source === "function") {
|
|
1082
|
+
return source();
|
|
1083
|
+
}
|
|
1084
|
+
return source;
|
|
1085
|
+
}
|
|
1086
|
+
var ObjectRefImpl = class {
|
|
1087
|
+
constructor(_object, _key) {
|
|
1088
|
+
this._object = _object;
|
|
1089
|
+
this._key = _key;
|
|
1090
|
+
this.__v_isRef = true;
|
|
1091
|
+
}
|
|
1092
|
+
get value() {
|
|
1093
|
+
return this._object[this._key];
|
|
1094
|
+
}
|
|
1095
|
+
set value(newVal) {
|
|
1096
|
+
this._object[this._key] = newVal;
|
|
1097
|
+
}
|
|
1098
|
+
};
|
|
1099
|
+
var CustomRefImpl = class {
|
|
1100
|
+
constructor(factory) {
|
|
1101
|
+
this.__v_isRef = true;
|
|
1102
|
+
this.dep = createDep();
|
|
1103
|
+
const { get, set: set2 } = factory(
|
|
1104
|
+
() => trackRefValue(this),
|
|
1105
|
+
() => triggerRefValue(this)
|
|
1106
|
+
);
|
|
1107
|
+
this._getter = get;
|
|
1108
|
+
this._setter = set2;
|
|
1109
|
+
}
|
|
1110
|
+
get value() {
|
|
1111
|
+
return this._getter();
|
|
1112
|
+
}
|
|
1113
|
+
set value(newVal) {
|
|
1114
|
+
this._setter(newVal);
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
function toReactive(value) {
|
|
1118
|
+
return commonIs.isObject(value) ? reactive(value) : value;
|
|
1119
|
+
}
|
|
1120
|
+
var MAX_COMPUTED_DEPTH = 100;
|
|
1121
|
+
var computedDepth = 0;
|
|
1122
|
+
var computedStack = /* @__PURE__ */ new Set();
|
|
1123
|
+
var _a;
|
|
1124
|
+
_a = ComputedRefSymbol;
|
|
1125
|
+
var _ComputedRefImpl = class _ComputedRefImpl {
|
|
1126
|
+
// 60秒后清理缓存
|
|
1127
|
+
constructor(getter, _setter, isSSR) {
|
|
1128
|
+
this._setter = _setter;
|
|
1129
|
+
// 使用 Dep 类型替代 Set<any>,提供更精确的类型约束
|
|
1130
|
+
this.dep = createDep();
|
|
1131
|
+
this._dirty = true;
|
|
1132
|
+
this._initialized = false;
|
|
1133
|
+
this[_a] = true;
|
|
1134
|
+
this.__v_isRef = true;
|
|
1135
|
+
this.__v_isComputed = true;
|
|
1136
|
+
// FIX: P2-6 计算属性缓存清理相关属性
|
|
1137
|
+
this._cacheCleanupTimer = null;
|
|
1138
|
+
this.effect = new ReactiveEffect(getter, () => {
|
|
1139
|
+
if (!this._dirty) {
|
|
1140
|
+
this._dirty = true;
|
|
1141
|
+
triggerRefValue(this);
|
|
1142
|
+
}
|
|
1143
|
+
this._resetCacheCleanupTimer();
|
|
1144
|
+
});
|
|
1145
|
+
this.effect.computed = true;
|
|
1146
|
+
const effect2 = this.effect;
|
|
1147
|
+
effect2.onStop = () => {
|
|
1148
|
+
this._cleanupCache();
|
|
1149
|
+
};
|
|
1150
|
+
if (isSSR) {
|
|
1151
|
+
try {
|
|
1152
|
+
this._value = getter();
|
|
1153
|
+
this._dirty = false;
|
|
1154
|
+
} catch (e) {
|
|
1155
|
+
this._dirty = true;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
// FIX: P2-6 重置缓存清理定时器
|
|
1160
|
+
_resetCacheCleanupTimer() {
|
|
1161
|
+
if (this._cacheCleanupTimer) {
|
|
1162
|
+
clearTimeout(this._cacheCleanupTimer);
|
|
1163
|
+
}
|
|
1164
|
+
this._cacheCleanupTimer = setTimeout(() => {
|
|
1165
|
+
if (!this.effect.active) {
|
|
1166
|
+
this._cleanupCache();
|
|
1167
|
+
}
|
|
1168
|
+
}, _ComputedRefImpl.CACHE_CLEANUP_DELAY);
|
|
1169
|
+
}
|
|
1170
|
+
// FIX: P2-6 清理缓存值
|
|
1171
|
+
_cleanupCache() {
|
|
1172
|
+
if (!this.effect.active) {
|
|
1173
|
+
if (this._cacheCleanupTimer) {
|
|
1174
|
+
clearTimeout(this._cacheCleanupTimer);
|
|
1175
|
+
this._cacheCleanupTimer = null;
|
|
1176
|
+
}
|
|
1177
|
+
this._value = commonAssertions.unsafeCast(void 0);
|
|
1178
|
+
this._initialized = false;
|
|
1179
|
+
this._dirty = true;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
// FIX: P2-6 手动清理缓存的公共方法
|
|
1183
|
+
/**
|
|
1184
|
+
* 手动清理计算属性的缓存值。
|
|
1185
|
+
* 在组件卸载时调用此方法可以释放内存。
|
|
1186
|
+
*/
|
|
1187
|
+
cleanupCache() {
|
|
1188
|
+
if (this._cacheCleanupTimer) {
|
|
1189
|
+
clearTimeout(this._cacheCleanupTimer);
|
|
1190
|
+
this._cacheCleanupTimer = null;
|
|
1191
|
+
}
|
|
1192
|
+
this._cleanupCache();
|
|
1193
|
+
}
|
|
1194
|
+
get value() {
|
|
1195
|
+
trackRefValue(this);
|
|
1196
|
+
if (this._dirty) {
|
|
1197
|
+
if (this.effect.active) {
|
|
1198
|
+
if (computedStack.has(this)) {
|
|
1199
|
+
throw new Error(
|
|
1200
|
+
`[LytJS/reactivity] Circular dependency detected in computed property. A computed property is indirectly referencing itself, causing an infinite loop.
|
|
1201
|
+
Error Code: CIRCULAR_REFERENCE (4008)
|
|
1202
|
+
Suggestion: Check your computed property dependencies and avoid referencing the computed itself or other computeds that depend on it.`
|
|
1203
|
+
);
|
|
1204
|
+
}
|
|
1205
|
+
computedDepth++;
|
|
1206
|
+
if (computedDepth > MAX_COMPUTED_DEPTH) {
|
|
1207
|
+
computedDepth--;
|
|
1208
|
+
throw new Error(
|
|
1209
|
+
`[LytJS/reactivity] Maximum computed depth exceeded (${MAX_COMPUTED_DEPTH}). Possible infinite loop in computed properties.
|
|
1210
|
+
Error Code: CIRCULAR_REFERENCE (4008)
|
|
1211
|
+
Suggestion: Check for circular dependencies in your computed properties.`
|
|
1212
|
+
);
|
|
1213
|
+
}
|
|
1214
|
+
computedStack.add(this);
|
|
1215
|
+
try {
|
|
1216
|
+
const value = this.effect.run();
|
|
1217
|
+
if (value !== void 0) {
|
|
1218
|
+
this._value = value;
|
|
1219
|
+
this._initialized = true;
|
|
1220
|
+
}
|
|
1221
|
+
this._dirty = false;
|
|
1222
|
+
} catch (e) {
|
|
1223
|
+
if (this._initialized) {
|
|
1224
|
+
this._dirty = false;
|
|
1225
|
+
}
|
|
1226
|
+
throw e;
|
|
1227
|
+
} finally {
|
|
1228
|
+
computedStack.delete(this);
|
|
1229
|
+
computedDepth--;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
return this._value;
|
|
1234
|
+
}
|
|
1235
|
+
set value(newValue) {
|
|
1236
|
+
if (this._setter) {
|
|
1237
|
+
this._setter(newValue);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
_ComputedRefImpl.CACHE_CLEANUP_DELAY = 6e4;
|
|
1242
|
+
var ComputedRefImpl = _ComputedRefImpl;
|
|
1243
|
+
var _isSSR = false;
|
|
1244
|
+
function setSSRMode(isSSR) {
|
|
1245
|
+
_isSSR = isSSR;
|
|
1246
|
+
}
|
|
1247
|
+
function computed2(getterOrOptions) {
|
|
1248
|
+
let getter;
|
|
1249
|
+
let setter;
|
|
1250
|
+
if (commonIs.isFunction(getterOrOptions)) {
|
|
1251
|
+
getter = getterOrOptions;
|
|
1252
|
+
setter = void 0;
|
|
1253
|
+
} else {
|
|
1254
|
+
getter = getterOrOptions.get;
|
|
1255
|
+
setter = getterOrOptions.set;
|
|
1256
|
+
}
|
|
1257
|
+
return new ComputedRefImpl(getter, setter, _isSSR);
|
|
1258
|
+
}
|
|
1259
|
+
function getSource(source) {
|
|
1260
|
+
if (isRef(source)) return () => source.value;
|
|
1261
|
+
if (commonIs.isObject(source) && isReactive(source)) return () => traverse(source);
|
|
1262
|
+
if (typeof source === "function") return source;
|
|
1263
|
+
return commonIs.NOOP;
|
|
1264
|
+
}
|
|
1265
|
+
var MAX_TRAVERSE_DEPTH = 100;
|
|
1266
|
+
function traverse(value, seen, depth = 0) {
|
|
1267
|
+
const _seen = /* @__PURE__ */ new Set();
|
|
1268
|
+
if (!commonIs.isObject(value) || _seen.has(value)) return value;
|
|
1269
|
+
const stack = [{ value, depth }];
|
|
1270
|
+
while (stack.length > 0) {
|
|
1271
|
+
const current = stack.pop();
|
|
1272
|
+
const { value: val, depth: d } = current;
|
|
1273
|
+
if (!commonIs.isObject(val) || _seen.has(val)) continue;
|
|
1274
|
+
if (d > MAX_TRAVERSE_DEPTH) {
|
|
1275
|
+
continue;
|
|
1276
|
+
}
|
|
1277
|
+
_seen.add(val);
|
|
1278
|
+
if (commonIs.isArray(val)) {
|
|
1279
|
+
for (let i = val.length - 1; i >= 0; i--) {
|
|
1280
|
+
stack.push({ value: val[i], depth: d + 1 });
|
|
1281
|
+
}
|
|
1282
|
+
} else if (val instanceof Map) {
|
|
1283
|
+
val.forEach((v, key) => {
|
|
1284
|
+
stack.push({ value: v, depth: d + 1 });
|
|
1285
|
+
if (commonIs.isObject(key)) {
|
|
1286
|
+
stack.push({ value: key, depth: d + 1 });
|
|
1287
|
+
}
|
|
1288
|
+
});
|
|
1289
|
+
} else if (val instanceof Set) {
|
|
1290
|
+
val.forEach((v) => {
|
|
1291
|
+
stack.push({ value: v, depth: d + 1 });
|
|
1292
|
+
});
|
|
1293
|
+
} else {
|
|
1294
|
+
const keys = Object.keys(val);
|
|
1295
|
+
for (let i = keys.length - 1; i >= 0; i--) {
|
|
1296
|
+
stack.push({
|
|
1297
|
+
value: val[keys[i]],
|
|
1298
|
+
depth: d + 1
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
return value;
|
|
1304
|
+
}
|
|
1305
|
+
function watch(source, cb, options) {
|
|
1306
|
+
const {
|
|
1307
|
+
immediate,
|
|
1308
|
+
deep,
|
|
1309
|
+
flush = "pre",
|
|
1310
|
+
once,
|
|
1311
|
+
onTrack,
|
|
1312
|
+
onTrigger,
|
|
1313
|
+
scheduler: userScheduler
|
|
1314
|
+
} = options || {};
|
|
1315
|
+
let getter;
|
|
1316
|
+
let forceTrigger = false;
|
|
1317
|
+
let isMultiSource = false;
|
|
1318
|
+
if (commonIs.isArray(source)) {
|
|
1319
|
+
isMultiSource = true;
|
|
1320
|
+
forceTrigger = source.some((s) => commonIs.isObject(s) && isReactive(s));
|
|
1321
|
+
getter = () => source.map((s) => {
|
|
1322
|
+
if (isRef(s)) return s.value;
|
|
1323
|
+
if (commonIs.isObject(s) && isReactive(s)) return traverse(s);
|
|
1324
|
+
if (commonIs.isFunction(s)) return s();
|
|
1325
|
+
return void 0;
|
|
1326
|
+
});
|
|
1327
|
+
} else {
|
|
1328
|
+
getter = getSource(source);
|
|
1329
|
+
if (commonIs.isObject(source) && isReactive(source)) {
|
|
1330
|
+
forceTrigger = true;
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
if (deep) {
|
|
1334
|
+
const baseGetter = getter;
|
|
1335
|
+
getter = () => traverse(baseGetter());
|
|
1336
|
+
}
|
|
1337
|
+
let oldValue = isMultiSource ? new Array(source.length).fill(void 0) : void 0;
|
|
1338
|
+
const cleanupFns = [];
|
|
1339
|
+
let isStopped = false;
|
|
1340
|
+
let consecutiveErrors = 0;
|
|
1341
|
+
const MAX_CONSECUTIVE_ERRORS = 3;
|
|
1342
|
+
const onCleanup = (fn) => {
|
|
1343
|
+
cleanupFns.push(fn);
|
|
1344
|
+
};
|
|
1345
|
+
const job = () => {
|
|
1346
|
+
if (!watcher.active || isStopped) return;
|
|
1347
|
+
if (cb) {
|
|
1348
|
+
let newValue;
|
|
1349
|
+
try {
|
|
1350
|
+
newValue = watcher.run();
|
|
1351
|
+
consecutiveErrors = 0;
|
|
1352
|
+
} catch (e) {
|
|
1353
|
+
consecutiveErrors++;
|
|
1354
|
+
if (consecutiveErrors <= MAX_CONSECUTIVE_ERRORS) {
|
|
1355
|
+
commonError.error(`Error in watch getter: ${e}`);
|
|
1356
|
+
}
|
|
1357
|
+
throw e;
|
|
1358
|
+
}
|
|
1359
|
+
if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => commonIs.hasChanged(v, oldValue[i])) : commonIs.hasChanged(newValue, oldValue))) {
|
|
1360
|
+
if (cleanupFns.length > 0) {
|
|
1361
|
+
cleanupFns.forEach((f) => f());
|
|
1362
|
+
cleanupFns.length = 0;
|
|
1363
|
+
}
|
|
1364
|
+
try {
|
|
1365
|
+
cb(
|
|
1366
|
+
newValue,
|
|
1367
|
+
oldValue,
|
|
1368
|
+
onCleanup
|
|
1369
|
+
);
|
|
1370
|
+
consecutiveErrors = 0;
|
|
1371
|
+
} catch (e) {
|
|
1372
|
+
consecutiveErrors++;
|
|
1373
|
+
if (consecutiveErrors <= MAX_CONSECUTIVE_ERRORS) {
|
|
1374
|
+
commonError.error(`Error in watch callback: ${e}`);
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
oldValue = newValue;
|
|
1378
|
+
if (once) {
|
|
1379
|
+
isStopped = true;
|
|
1380
|
+
watcher.stop();
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
} else {
|
|
1384
|
+
try {
|
|
1385
|
+
watcher.run();
|
|
1386
|
+
consecutiveErrors = 0;
|
|
1387
|
+
} catch (e) {
|
|
1388
|
+
consecutiveErrors++;
|
|
1389
|
+
if (consecutiveErrors <= MAX_CONSECUTIVE_ERRORS) {
|
|
1390
|
+
commonError.error(`Error in watch effect run: ${e}`);
|
|
1391
|
+
}
|
|
1392
|
+
throw e;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
const rawScheduler = userScheduler || (flush === "sync" ? job : () => {
|
|
1397
|
+
if (flush === "post") {
|
|
1398
|
+
commonScheduler.queuePostFlushCb(job);
|
|
1399
|
+
} else {
|
|
1400
|
+
commonScheduler.queuePreFlushCb(job);
|
|
1401
|
+
}
|
|
1402
|
+
});
|
|
1403
|
+
const scheduler = userScheduler ? (...args) => rawScheduler(job, ...args) : rawScheduler;
|
|
1404
|
+
const watcher = new ReactiveEffect(getter, scheduler);
|
|
1405
|
+
watcher.onStop = () => {
|
|
1406
|
+
if (cleanupFns.length > 0) {
|
|
1407
|
+
for (let i = cleanupFns.length - 1; i >= 0; i--) {
|
|
1408
|
+
cleanupFns[i]();
|
|
1409
|
+
}
|
|
1410
|
+
cleanupFns.length = 0;
|
|
1411
|
+
}
|
|
1412
|
+
};
|
|
1413
|
+
if (immediate) {
|
|
1414
|
+
job();
|
|
1415
|
+
} else {
|
|
1416
|
+
oldValue = watcher.run();
|
|
1417
|
+
}
|
|
1418
|
+
return () => {
|
|
1419
|
+
if (isStopped) return;
|
|
1420
|
+
isStopped = true;
|
|
1421
|
+
watcher.stop();
|
|
1422
|
+
getter = () => {
|
|
1423
|
+
};
|
|
1424
|
+
cleanupFns.length = 0;
|
|
1425
|
+
cb = commonIs.NOOP;
|
|
1426
|
+
oldValue = void 0;
|
|
1427
|
+
consecutiveErrors = 0;
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
function watchEffect(effectFn, options) {
|
|
1431
|
+
return doWatchEffect(effectFn, options);
|
|
1432
|
+
}
|
|
1433
|
+
function watchPostEffect(effectFn, options) {
|
|
1434
|
+
return doWatchEffect(effectFn, { ...options, flush: "post" });
|
|
1435
|
+
}
|
|
1436
|
+
function watchSyncEffect(effectFn, options) {
|
|
1437
|
+
return doWatchEffect(effectFn, { ...options, flush: "sync" });
|
|
1438
|
+
}
|
|
1439
|
+
function doWatchEffect(source, options = {}) {
|
|
1440
|
+
const { flush = "pre", onTrack, onTrigger } = options;
|
|
1441
|
+
const cleanupFns = [];
|
|
1442
|
+
let isStopped = false;
|
|
1443
|
+
const onCleanup = (fn) => {
|
|
1444
|
+
cleanupFns.push(fn);
|
|
1445
|
+
};
|
|
1446
|
+
const getter = () => {
|
|
1447
|
+
if (cleanupFns.length > 0) {
|
|
1448
|
+
cleanupFns.forEach((f) => f());
|
|
1449
|
+
cleanupFns.length = 0;
|
|
1450
|
+
}
|
|
1451
|
+
source(onCleanup);
|
|
1452
|
+
};
|
|
1453
|
+
let effectRef;
|
|
1454
|
+
const schedulerFn = flush === "sync" ? () => effectRef?.run() : () => {
|
|
1455
|
+
if (flush === "post") {
|
|
1456
|
+
commonScheduler.queuePostFlushCb(() => effectRef?.run());
|
|
1457
|
+
} else {
|
|
1458
|
+
commonScheduler.queuePreFlushCb(() => effectRef?.run());
|
|
1459
|
+
}
|
|
1460
|
+
};
|
|
1461
|
+
const currentEffect = new ReactiveEffect(getter, schedulerFn);
|
|
1462
|
+
effectRef = currentEffect;
|
|
1463
|
+
currentEffect.onStop = () => {
|
|
1464
|
+
if (cleanupFns.length > 0) {
|
|
1465
|
+
for (let i = cleanupFns.length - 1; i >= 0; i--) {
|
|
1466
|
+
cleanupFns[i]();
|
|
1467
|
+
}
|
|
1468
|
+
cleanupFns.length = 0;
|
|
1469
|
+
}
|
|
1470
|
+
};
|
|
1471
|
+
currentEffect.run();
|
|
1472
|
+
return () => {
|
|
1473
|
+
if (isStopped) return;
|
|
1474
|
+
isStopped = true;
|
|
1475
|
+
currentEffect.stop();
|
|
1476
|
+
cleanupFns.length = 0;
|
|
1477
|
+
source = commonIs.NOOP;
|
|
1478
|
+
effectRef = void 0;
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
// src/batch.ts
|
|
1483
|
+
var scopeStack = [];
|
|
1484
|
+
var globalBatchDepth = 0;
|
|
1485
|
+
var MAX_NESTING_DEPTH = 100;
|
|
1486
|
+
function batchScope(callback, options = {}) {
|
|
1487
|
+
const { async = false, name = "batchScope", onError } = options;
|
|
1488
|
+
if (globalBatchDepth >= MAX_NESTING_DEPTH) {
|
|
1489
|
+
const error3 = new Error(
|
|
1490
|
+
`[lytjs/reactivity] Maximum batchScope nesting depth (${MAX_NESTING_DEPTH}) exceeded. This may indicate an infinite loop.`
|
|
1491
|
+
);
|
|
1492
|
+
if (onError) {
|
|
1493
|
+
onError(error3);
|
|
1494
|
+
throw error3;
|
|
1495
|
+
}
|
|
1496
|
+
throw error3;
|
|
1497
|
+
}
|
|
1498
|
+
const ctx = {
|
|
1499
|
+
depth: globalBatchDepth,
|
|
1500
|
+
name,
|
|
1501
|
+
committed: false,
|
|
1502
|
+
cancelled: false
|
|
1503
|
+
};
|
|
1504
|
+
scopeStack.push(ctx);
|
|
1505
|
+
globalBatchDepth++;
|
|
1506
|
+
try {
|
|
1507
|
+
if (async) {
|
|
1508
|
+
let result;
|
|
1509
|
+
const promise = batchAsync(() => {
|
|
1510
|
+
result = callback(ctx);
|
|
1511
|
+
});
|
|
1512
|
+
promise.then(() => {
|
|
1513
|
+
ctx.committed = true;
|
|
1514
|
+
scopeStack.pop();
|
|
1515
|
+
globalBatchDepth--;
|
|
1516
|
+
}).catch((error3) => {
|
|
1517
|
+
scopeStack.pop();
|
|
1518
|
+
globalBatchDepth--;
|
|
1519
|
+
if (onError) {
|
|
1520
|
+
onError(error3);
|
|
1521
|
+
} else {
|
|
1522
|
+
throw error3;
|
|
1523
|
+
}
|
|
1524
|
+
});
|
|
1525
|
+
return result;
|
|
1526
|
+
} else {
|
|
1527
|
+
let result;
|
|
1528
|
+
batch(() => {
|
|
1529
|
+
result = callback(ctx);
|
|
1530
|
+
});
|
|
1531
|
+
ctx.committed = true;
|
|
1532
|
+
if (result === void 0) {
|
|
1533
|
+
throw new Error(
|
|
1534
|
+
"[lytjs/reactivity] batchScope sync mode: callback returned undefined."
|
|
1535
|
+
);
|
|
1536
|
+
}
|
|
1537
|
+
return result;
|
|
1538
|
+
}
|
|
1539
|
+
} catch (error3) {
|
|
1540
|
+
if (onError) {
|
|
1541
|
+
onError(error3);
|
|
1542
|
+
throw error3;
|
|
1543
|
+
}
|
|
1544
|
+
throw error3;
|
|
1545
|
+
} finally {
|
|
1546
|
+
if (!async) {
|
|
1547
|
+
scopeStack.pop();
|
|
1548
|
+
globalBatchDepth--;
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
async function batchScopeAsync(callback, options = {}) {
|
|
1553
|
+
const { name = "batchScopeAsync", onError } = options;
|
|
1554
|
+
if (globalBatchDepth >= MAX_NESTING_DEPTH) {
|
|
1555
|
+
const error3 = new Error(
|
|
1556
|
+
`[lytjs/reactivity] Maximum batchScope nesting depth (${MAX_NESTING_DEPTH}) exceeded.`
|
|
1557
|
+
);
|
|
1558
|
+
if (onError) {
|
|
1559
|
+
onError(error3);
|
|
1560
|
+
return Promise.reject(error3);
|
|
1561
|
+
}
|
|
1562
|
+
return Promise.reject(error3);
|
|
1563
|
+
}
|
|
1564
|
+
const ctx = {
|
|
1565
|
+
depth: globalBatchDepth,
|
|
1566
|
+
name,
|
|
1567
|
+
committed: false,
|
|
1568
|
+
cancelled: false
|
|
1569
|
+
};
|
|
1570
|
+
scopeStack.push(ctx);
|
|
1571
|
+
globalBatchDepth++;
|
|
1572
|
+
try {
|
|
1573
|
+
let result;
|
|
1574
|
+
await batchAsync(async () => {
|
|
1575
|
+
result = await callback(ctx);
|
|
1576
|
+
});
|
|
1577
|
+
ctx.committed = true;
|
|
1578
|
+
return result;
|
|
1579
|
+
} catch (error3) {
|
|
1580
|
+
if (onError) {
|
|
1581
|
+
onError(error3);
|
|
1582
|
+
throw error3;
|
|
1583
|
+
}
|
|
1584
|
+
throw error3;
|
|
1585
|
+
} finally {
|
|
1586
|
+
scopeStack.pop();
|
|
1587
|
+
globalBatchDepth--;
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
function batchScopeUntrack(fn) {
|
|
1591
|
+
return untrack(fn);
|
|
1592
|
+
}
|
|
1593
|
+
function getBatchScopeDepth() {
|
|
1594
|
+
return globalBatchDepth;
|
|
1595
|
+
}
|
|
1596
|
+
function getCurrentBatchScopeStack() {
|
|
1597
|
+
return [...scopeStack];
|
|
1598
|
+
}
|
|
1599
|
+
function isInBatchScope() {
|
|
1600
|
+
return globalBatchDepth > 0;
|
|
1601
|
+
}
|
|
1602
|
+
function flushBatchScopes() {
|
|
1603
|
+
return Promise.resolve();
|
|
1604
|
+
}
|
|
1605
|
+
function _notifyDevToolsSignalChange(signalId, value) {
|
|
1606
|
+
return;
|
|
1607
|
+
}
|
|
1608
|
+
function _notifyDevToolsEffectRun(effectId) {
|
|
1609
|
+
return;
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
exports.ComputedRefSymbol = ComputedRefSymbol;
|
|
1613
|
+
exports.ReactiveSymbol = ReactiveSymbol;
|
|
1614
|
+
exports.ReadonlySymbol = ReadonlySymbol;
|
|
1615
|
+
exports.RefSymbol = RefSymbol;
|
|
1616
|
+
exports.ShallowRefSymbol = ShallowRefSymbol;
|
|
1617
|
+
exports._notifyDevToolsEffectRun = _notifyDevToolsEffectRun;
|
|
1618
|
+
exports._notifyDevToolsSignalChange = _notifyDevToolsSignalChange;
|
|
1619
|
+
exports.batch = batch;
|
|
1620
|
+
exports.batchAsync = batchAsync;
|
|
1621
|
+
exports.batchScope = batchScope;
|
|
1622
|
+
exports.batchScopeAsync = batchScopeAsync;
|
|
1623
|
+
exports.batchScopeUntrack = batchScopeUntrack;
|
|
1624
|
+
exports.computed = computed2;
|
|
1625
|
+
exports.computedSignal = computedSignal;
|
|
1626
|
+
exports.customRef = customRef;
|
|
1627
|
+
exports.effect = effect;
|
|
1628
|
+
exports.effectScope = effectScope;
|
|
1629
|
+
exports.enableTracking = enableTracking;
|
|
1630
|
+
exports.flushBatchScopes = flushBatchScopes;
|
|
1631
|
+
exports.getBatchScopeDepth = getBatchScopeDepth;
|
|
1632
|
+
exports.getCurrentBatchScopeStack = getCurrentBatchScopeStack;
|
|
1633
|
+
exports.getCurrentScope = getCurrentScope;
|
|
1634
|
+
exports.getSkippedTrackingCount = getSkippedTrackingCount;
|
|
1635
|
+
exports.isComputedRef = isComputedRef;
|
|
1636
|
+
exports.isInBatchScope = isInBatchScope;
|
|
1637
|
+
exports.isProxy = isProxy;
|
|
1638
|
+
exports.isReactive = isReactive;
|
|
1639
|
+
exports.isReadonly = isReadonly;
|
|
1640
|
+
exports.isRef = isRef;
|
|
1641
|
+
exports.isShallowRef = isShallowRef;
|
|
1642
|
+
exports.markRaw = markRaw;
|
|
1643
|
+
exports.onEffectCleanup = onEffectCleanup;
|
|
1644
|
+
exports.onScopeDispose = onScopeDispose;
|
|
1645
|
+
exports.pauseTracking = pauseTracking;
|
|
1646
|
+
exports.reactive = reactive;
|
|
1647
|
+
exports.readonly = readonly;
|
|
1648
|
+
exports.readonlySignal = readonlySignal;
|
|
1649
|
+
exports.ref = ref;
|
|
1650
|
+
exports.resetSkippedTrackingCount = resetSkippedTrackingCount;
|
|
1651
|
+
exports.resetTracking = resetTracking;
|
|
1652
|
+
exports.set = set;
|
|
1653
|
+
exports.setSSRMode = setSSRMode;
|
|
1654
|
+
exports.shallowReactive = shallowReactive;
|
|
1655
|
+
exports.shallowReadonly = shallowReadonly;
|
|
1656
|
+
exports.shallowRef = shallowRef;
|
|
1657
|
+
exports.shouldSkipTracking = shouldSkipTracking;
|
|
1658
|
+
exports.signal = signal;
|
|
1659
|
+
exports.signalBatch = signalBatch;
|
|
1660
|
+
exports.signalComputed = computed;
|
|
1661
|
+
exports.signalUntrack = signalUntrack;
|
|
1662
|
+
exports.stop = stop;
|
|
1663
|
+
exports.toRaw = toRaw;
|
|
1664
|
+
exports.toRef = toRef;
|
|
1665
|
+
exports.toRefs = toRefs;
|
|
1666
|
+
exports.toValue = toValue;
|
|
1667
|
+
exports.triggerRef = triggerRef;
|
|
1668
|
+
exports.unref = unref;
|
|
1669
|
+
exports.untrack = untrack;
|
|
1670
|
+
exports.update = update;
|
|
1671
|
+
exports.valueOf = valueOf;
|
|
1672
|
+
exports.watch = watch;
|
|
1673
|
+
exports.watchEffect = watchEffect;
|
|
1674
|
+
exports.watchPostEffect = watchPostEffect;
|
|
1675
|
+
exports.watchSyncEffect = watchSyncEffect;
|
|
1676
|
+
exports.withFirstRenderOptimization = withFirstRenderOptimization;
|
|
1677
|
+
exports.writableComputedSignal = writableComputedSignal;
|
|
1678
|
+
//# sourceMappingURL=index.cjs.map
|
|
1679
|
+
//# sourceMappingURL=index.cjs.map
|