@geodaoyu/accessor 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1 -0
- package/dist/index.es.js +900 -0
- package/dist/index.umd.js +1 -0
- package/package.json +16 -6
- package/src/Accessor.js +10 -0
- package/src/index.js +2 -0
- package/src/reactiveUtils.js +5 -0
- package/src/accessor.ts +0 -119
- package/src/index.ts +0 -3
- package/test/construct.test.js +0 -31
- package/test/get.test.js +0 -34
- package/test/set.test.js +0 -56
- package/test/watch.test.js +0 -168
- package/tsconfig.json +0 -19
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function Lt(t){const e=Object.create(null);for(const n of t.split(","))e[n]=1;return n=>n in e}const Wt=process.env.NODE_ENV!=="production"?Object.freeze({}):{};process.env.NODE_ENV!=="production"&&Object.freeze([]);const Ht=()=>{},ot=Object.assign,$t=Object.prototype.hasOwnProperty,ct=(t,e)=>$t.call(t,e),V=Array.isArray,P=t=>et(t)==="[object Map]",Ct=t=>et(t)==="[object Set]",wt=t=>typeof t=="function",zt=t=>typeof t=="string",F=t=>typeof t=="symbol",K=t=>t!==null&&typeof t=="object",Yt=Object.prototype.toString,et=t=>Yt.call(t),yt=t=>et(t).slice(8,-1),Bt=t=>et(t)==="[object Object]",dt=t=>zt(t)&&t!=="NaN"&&t[0]!=="-"&&""+parseInt(t,10)===t,Ft=t=>{const e=Object.create(null);return(n=>e[n]||(e[n]=t(n)))},Ut=Ft(t=>t.charAt(0).toUpperCase()+t.slice(1)),m=(t,e)=>!Object.is(t,e);function S(t,...e){console.warn(`[Vue warn] ${t}`,...e)}let u;const rt=new WeakSet;class Gt{constructor(e){this.fn=e,this.deps=void 0,this.depsTail=void 0,this.flags=5,this.next=void 0,this.cleanup=void 0,this.scheduler=void 0}pause(){this.flags|=64}resume(){this.flags&64&&(this.flags&=-65,rt.has(this)&&(rt.delete(this),this.trigger()))}notify(){this.flags&2&&!(this.flags&32)||this.flags&8||Jt(this)}run(){if(!(this.flags&1))return this.fn();this.flags|=2,Et(this),Nt(this);const e=u,n=g;u=this,g=!0;try{return this.fn()}finally{process.env.NODE_ENV!=="production"&&u!==this&&S("Active effect was not restored correctly - this is likely a Vue internal bug."),xt(this),u=e,g=n,this.flags&=-3}}stop(){if(this.flags&1){for(let e=this.deps;e;e=e.nextDep)_t(e);this.deps=this.depsTail=void 0,Et(this),this.onStop&&this.onStop(),this.flags&=-2}}trigger(){this.flags&64?rt.add(this):this.scheduler?this.scheduler():this.runIfDirty()}runIfDirty(){at(this)&&this.run()}get dirty(){return at(this)}}let Dt=0,$,C;function Jt(t,e=!1){if(t.flags|=8,e){t.next=C,C=t;return}t.next=$,$=t}function ht(){Dt++}function vt(){if(--Dt>0)return;if(C){let e=C;for(C=void 0;e;){const n=e.next;e.next=void 0,e.flags&=-9,e=n}}let t;for(;$;){let e=$;for($=void 0;e;){const n=e.next;if(e.next=void 0,e.flags&=-9,e.flags&1)try{e.trigger()}catch(s){t||(t=s)}e=n}}if(t)throw t}function Nt(t){for(let e=t.deps;e;e=e.nextDep)e.version=-1,e.prevActiveLink=e.dep.activeLink,e.dep.activeLink=e}function xt(t){let e,n=t.depsTail,s=n;for(;s;){const r=s.prevDep;s.version===-1?(s===n&&(n=r),_t(s),qt(s)):e=s,s.dep.activeLink=s.prevActiveLink,s.prevActiveLink=void 0,s=r}t.deps=e,t.depsTail=n}function at(t){for(let e=t.deps;e;e=e.nextDep)if(e.dep.version!==e.version||e.dep.computed&&(Qt(e.dep.computed)||e.dep.version!==e.version))return!0;return!!t._dirty}function Qt(t){if(t.flags&4&&!(t.flags&16)||(t.flags&=-17,t.globalVersion===k)||(t.globalVersion=k,!t.isSSR&&t.flags&128&&(!t.deps&&!t._dirty||!at(t))))return;t.flags|=2;const e=t.dep,n=u,s=g;u=t,g=!0;try{Nt(t);const r=t.fn(t._value);(e.version===0||m(r,t._value))&&(t.flags|=128,t._value=r,e.version++)}catch(r){throw e.version++,r}finally{u=n,g=s,xt(t),t.flags&=-3}}function _t(t,e=!1){const{dep:n,prevSub:s,nextSub:r}=t;if(s&&(s.nextSub=r,t.prevSub=void 0),r&&(r.prevSub=s,t.nextSub=void 0),process.env.NODE_ENV!=="production"&&n.subsHead===t&&(n.subsHead=r),n.subs===t&&(n.subs=s,!s&&n.computed)){n.computed.flags&=-5;for(let i=n.computed.deps;i;i=i.nextDep)_t(i,!0)}!e&&!--n.sc&&n.map&&n.map.delete(n.key)}function qt(t){const{prevDep:e,nextDep:n}=t;e&&(e.nextDep=n,t.prevDep=void 0),n&&(n.prevDep=e,t.nextDep=void 0)}let g=!0;const Tt=[];function mt(){Tt.push(g),g=!1}function Rt(){const t=Tt.pop();g=t===void 0?!0:t}function Et(t){const{cleanup:e}=t;if(t.cleanup=void 0,e){const n=u;u=void 0;try{e()}finally{u=n}}}let k=0;class Xt{constructor(e,n){this.sub=e,this.dep=n,this.version=n.version,this.nextDep=this.prevDep=this.nextSub=this.prevSub=this.prevActiveLink=void 0}}class Zt{constructor(e){this.computed=e,this.version=0,this.activeLink=void 0,this.subs=void 0,this.map=void 0,this.key=void 0,this.sc=0,this.__v_skip=!0,process.env.NODE_ENV!=="production"&&(this.subsHead=void 0)}track(e){if(!u||!g||u===this.computed)return;let n=this.activeLink;if(n===void 0||n.sub!==u)n=this.activeLink=new Xt(u,this),u.deps?(n.prevDep=u.depsTail,u.depsTail.nextDep=n,u.depsTail=n):u.deps=u.depsTail=n,Vt(n);else if(n.version===-1&&(n.version=this.version,n.nextDep)){const s=n.nextDep;s.prevDep=n.prevDep,n.prevDep&&(n.prevDep.nextDep=s),n.prevDep=u.depsTail,n.nextDep=void 0,u.depsTail.nextDep=n,u.depsTail=n,u.deps===n&&(u.deps=s)}return process.env.NODE_ENV!=="production"&&u.onTrack&&u.onTrack(ot({effect:u},e)),n}trigger(e){this.version++,k++,this.notify(e)}notify(e){ht();try{if(process.env.NODE_ENV!=="production")for(let n=this.subsHead;n;n=n.nextSub)n.sub.onTrigger&&!(n.sub.flags&8)&&n.sub.onTrigger(ot({effect:n.sub},e));for(let n=this.subs;n;n=n.prevSub)n.sub.notify()&&n.sub.dep.notify()}finally{vt()}}}function Vt(t){if(t.dep.sc++,t.sub.flags&4){const e=t.dep.computed;if(e&&!t.dep.subs){e.flags|=20;for(let s=e.deps;s;s=s.nextDep)Vt(s)}const n=t.dep.subs;n!==t&&(t.prevSub=n,n&&(n.nextSub=t)),process.env.NODE_ENV!=="production"&&t.dep.subsHead===void 0&&(t.dep.subsHead=t),t.dep.subs=t}}const ft=new WeakMap,R=Symbol(process.env.NODE_ENV!=="production"?"Object iterate":""),lt=Symbol(process.env.NODE_ENV!=="production"?"Map keys iterate":""),Y=Symbol(process.env.NODE_ENV!=="production"?"Array iterate":"");function _(t,e,n){if(g&&u){let s=ft.get(t);s||ft.set(t,s=new Map);let r=s.get(n);r||(s.set(n,r=new Zt),r.map=s,r.key=n),process.env.NODE_ENV!=="production"?r.track({target:t,type:e,key:n}):r.track()}}function y(t,e,n,s,r,i){const o=ft.get(t);if(!o){k++;return}const c=a=>{a&&(process.env.NODE_ENV!=="production"?a.trigger({target:t,type:e,key:n,newValue:s,oldValue:r,oldTarget:i}):a.trigger())};if(ht(),e==="clear")o.forEach(c);else{const a=V(t),d=a&&dt(n);if(a&&n==="length"){const v=Number(s);o.forEach((f,h)=>{(h==="length"||h===Y||!F(h)&&h>=v)&&c(f)})}else switch((n!==void 0||o.has(void 0))&&c(o.get(n)),d&&c(o.get(Y)),e){case"add":a?d&&c(o.get("length")):(c(o.get(R)),P(t)&&c(o.get(lt)));break;case"delete":a||(c(o.get(R)),P(t)&&c(o.get(lt)));break;case"set":P(t)&&c(o.get(R));break}}vt()}function A(t){const e=p(t);return e===t?e:(_(e,"iterate",Y),w(t)?e:e.map(I))}function gt(t){return _(t=p(t),"iterate",Y),t}function O(t,e){return j(t)?z(t)?B(I(e)):B(e):I(e)}const kt={__proto__:null,[Symbol.iterator](){return st(this,Symbol.iterator,t=>O(this,t))},concat(...t){return A(this).concat(...t.map(e=>V(e)?A(e):e))},entries(){return st(this,"entries",t=>(t[1]=O(this,t[1]),t))},every(t,e){return E(this,"every",t,e,void 0,arguments)},filter(t,e){return E(this,"filter",t,e,n=>n.map(s=>O(this,s)),arguments)},find(t,e){return E(this,"find",t,e,n=>O(this,n),arguments)},findIndex(t,e){return E(this,"findIndex",t,e,void 0,arguments)},findLast(t,e){return E(this,"findLast",t,e,n=>O(this,n),arguments)},findLastIndex(t,e){return E(this,"findLastIndex",t,e,void 0,arguments)},forEach(t,e){return E(this,"forEach",t,e,void 0,arguments)},includes(...t){return it(this,"includes",t)},indexOf(...t){return it(this,"indexOf",t)},join(t){return A(this).join(t)},lastIndexOf(...t){return it(this,"lastIndexOf",t)},map(t,e){return E(this,"map",t,e,void 0,arguments)},pop(){return H(this,"pop")},push(...t){return H(this,"push",t)},reduce(t,...e){return St(this,"reduce",t,e)},reduceRight(t,...e){return St(this,"reduceRight",t,e)},shift(){return H(this,"shift")},some(t,e){return E(this,"some",t,e,void 0,arguments)},splice(...t){return H(this,"splice",t)},toReversed(){return A(this).toReversed()},toSorted(t){return A(this).toSorted(t)},toSpliced(...t){return A(this).toSpliced(...t)},unshift(...t){return H(this,"unshift",t)},values(){return st(this,"values",t=>O(this,t))}};function st(t,e,n){const s=gt(t),r=s[e]();return s!==t&&!w(t)&&(r._next=r.next,r.next=()=>{const i=r._next();return i.done||(i.value=n(i.value)),i}),r}const te=Array.prototype;function E(t,e,n,s,r,i){const o=gt(t),c=o!==t&&!w(t),a=o[e];if(a!==te[e]){const f=a.apply(t,i);return c?I(f):f}let d=n;o!==t&&(c?d=function(f,h){return n.call(this,O(t,f),h,t)}:n.length>2&&(d=function(f,h){return n.call(this,f,h,t)}));const v=a.call(o,d,s);return c&&r?r(v):v}function St(t,e,n,s){const r=gt(t);let i=n;return r!==t&&(w(t)?n.length>3&&(i=function(o,c,a){return n.call(this,o,c,a,t)}):i=function(o,c,a){return n.call(this,o,O(t,c),a,t)}),r[e](i,...s)}function it(t,e,n){const s=p(t);_(s,"iterate",Y);const r=s[e](...n);return(r===-1||r===!1)&&ve(n[0])?(n[0]=p(n[0]),s[e](...n)):r}function H(t,e,n=[]){mt(),ht();const s=p(t)[e].apply(t,n);return vt(),Rt(),s}const ee=Lt("__proto__,__v_isRef,__isVue"),jt=new Set(Object.getOwnPropertyNames(Symbol).filter(t=>t!=="arguments"&&t!=="caller").map(t=>Symbol[t]).filter(F));function ne(t){F(t)||(t=String(t));const e=p(this);return _(e,"has",t),e.hasOwnProperty(t)}class It{constructor(e=!1,n=!1){this._isReadonly=e,this._isShallow=n}get(e,n,s){if(n==="__v_skip")return e.__v_skip;const r=this._isReadonly,i=this._isShallow;if(n==="__v_isReactive")return!r;if(n==="__v_isReadonly")return r;if(n==="__v_isShallow")return i;if(n==="__v_raw")return s===(r?i?pe:Pt:i?ue:At).get(e)||Object.getPrototypeOf(e)===Object.getPrototypeOf(s)?e:void 0;const o=V(e);if(!r){let a;if(o&&(a=kt[n]))return a;if(n==="hasOwnProperty")return ne}const c=Reflect.get(e,n,N(e)?e:s);if((F(n)?jt.has(n):ee(n))||(r||_(e,"get",n),i))return c;if(N(c)){const a=o&&dt(n)?c:c.value;return r&&K(a)?pt(a):a}return K(c)?r?pt(c):bt(c):c}}class re extends It{constructor(e=!1){super(!1,e)}set(e,n,s,r){let i=e[n];const o=V(e)&&dt(n);if(!this._isShallow){const d=j(i);if(!w(s)&&!j(s)&&(i=p(i),s=p(s)),!o&&N(i)&&!N(s))return d?(process.env.NODE_ENV!=="production"&&S(`Set operation on key "${String(n)}" failed: target is readonly.`,e[n]),!0):(i.value=s,!0)}const c=o?Number(n)<e.length:ct(e,n),a=Reflect.set(e,n,s,N(e)?e:r);return e===p(r)&&(c?m(s,i)&&y(e,"set",n,s,i):y(e,"add",n,s)),a}deleteProperty(e,n){const s=ct(e,n),r=e[n],i=Reflect.deleteProperty(e,n);return i&&s&&y(e,"delete",n,void 0,r),i}has(e,n){const s=Reflect.has(e,n);return(!F(n)||!jt.has(n))&&_(e,"has",n),s}ownKeys(e){return _(e,"iterate",V(e)?"length":R),Reflect.ownKeys(e)}}class se extends It{constructor(e=!1){super(!0,e)}set(e,n){return process.env.NODE_ENV!=="production"&&S(`Set operation on key "${String(n)}" failed: target is readonly.`,e),!0}deleteProperty(e,n){return process.env.NODE_ENV!=="production"&&S(`Delete operation on key "${String(n)}" failed: target is readonly.`,e),!0}}const ie=new re,oe=new se,ut=t=>t,q=t=>Reflect.getPrototypeOf(t);function ce(t,e,n){return function(...s){const r=this.__v_raw,i=p(r),o=P(i),c=t==="entries"||t===Symbol.iterator&&o,a=t==="keys"&&o,d=r[t](...s),v=n?ut:e?B:I;return!e&&_(i,"iterate",a?lt:R),{next(){const{value:f,done:h}=d.next();return h?{value:f,done:h}:{value:c?[v(f[0]),v(f[1])]:v(f),done:h}},[Symbol.iterator](){return this}}}}function X(t){return function(...e){if(process.env.NODE_ENV!=="production"){const n=e[0]?`on key "${e[0]}" `:"";S(`${Ut(t)} operation ${n}failed: target is readonly.`,p(this))}return t==="delete"?!1:t==="clear"?void 0:this}}function ae(t,e){const n={get(r){const i=this.__v_raw,o=p(i),c=p(r);t||(m(r,c)&&_(o,"get",r),_(o,"get",c));const{has:a}=q(o),d=e?ut:t?B:I;if(a.call(o,r))return d(i.get(r));if(a.call(o,c))return d(i.get(c));i!==o&&i.get(r)},get size(){const r=this.__v_raw;return!t&&_(p(r),"iterate",R),r.size},has(r){const i=this.__v_raw,o=p(i),c=p(r);return t||(m(r,c)&&_(o,"has",r),_(o,"has",c)),r===c?i.has(r):i.has(r)||i.has(c)},forEach(r,i){const o=this,c=o.__v_raw,a=p(c),d=e?ut:t?B:I;return!t&&_(a,"iterate",R),c.forEach((v,f)=>r.call(i,d(v),d(f),o))}};return ot(n,t?{add:X("add"),set:X("set"),delete:X("delete"),clear:X("clear")}:{add(r){!e&&!w(r)&&!j(r)&&(r=p(r));const i=p(this);return q(i).has.call(i,r)||(i.add(r),y(i,"add",r,r)),this},set(r,i){!e&&!w(i)&&!j(i)&&(i=p(i));const o=p(this),{has:c,get:a}=q(o);let d=c.call(o,r);d?process.env.NODE_ENV!=="production"&&Ot(o,c,r):(r=p(r),d=c.call(o,r));const v=a.call(o,r);return o.set(r,i),d?m(i,v)&&y(o,"set",r,i,v):y(o,"add",r,i),this},delete(r){const i=p(this),{has:o,get:c}=q(i);let a=o.call(i,r);a?process.env.NODE_ENV!=="production"&&Ot(i,o,r):(r=p(r),a=o.call(i,r));const d=c?c.call(i,r):void 0,v=i.delete(r);return a&&y(i,"delete",r,void 0,d),v},clear(){const r=p(this),i=r.size!==0,o=process.env.NODE_ENV!=="production"?P(r)?new Map(r):new Set(r):void 0,c=r.clear();return i&&y(r,"clear",void 0,void 0,o),c}}),["keys","values","entries",Symbol.iterator].forEach(r=>{n[r]=ce(r,t,e)}),n}function Mt(t,e){const n=ae(t,e);return(s,r,i)=>r==="__v_isReactive"?!t:r==="__v_isReadonly"?t:r==="__v_raw"?s:Reflect.get(ct(n,r)&&r in s?n:s,r,i)}const fe={get:Mt(!1,!1)},le={get:Mt(!0,!1)};function Ot(t,e,n){const s=p(n);if(s!==n&&e.call(t,s)){const r=yt(t);S(`Reactive ${r} contains both the raw and reactive versions of the same object${r==="Map"?" as keys":""}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`)}}const At=new WeakMap,ue=new WeakMap,Pt=new WeakMap,pe=new WeakMap;function de(t){switch(t){case"Object":case"Array":return 1;case"Map":case"Set":case"WeakMap":case"WeakSet":return 2;default:return 0}}function he(t){return t.__v_skip||!Object.isExtensible(t)?0:de(yt(t))}function bt(t){return j(t)?t:Kt(t,!1,ie,fe,At)}function pt(t){return Kt(t,!0,oe,le,Pt)}function Kt(t,e,n,s,r){if(!K(t))return process.env.NODE_ENV!=="production"&&S(`value cannot be made ${e?"readonly":"reactive"}: ${String(t)}`),t;if(t.__v_raw&&!(e&&t.__v_isReactive))return t;const i=he(t);if(i===0)return t;const o=r.get(t);if(o)return o;const c=new Proxy(t,i===2?s:n);return r.set(t,c),c}function z(t){return j(t)?z(t.__v_raw):!!(t&&t.__v_isReactive)}function j(t){return!!(t&&t.__v_isReadonly)}function w(t){return!!(t&&t.__v_isShallow)}function ve(t){return t?!!t.__v_raw:!1}function p(t){const e=t&&t.__v_raw;return e?p(e):t}const I=t=>K(t)?bt(t):t,B=t=>K(t)?pt(t):t;function N(t){return t?t.__v_isRef===!0:!1}const Z={},tt=new WeakMap;let T;function _e(t,e=!1,n=T){if(n){let s=tt.get(n);s||tt.set(n,s=[]),s.push(t)}else process.env.NODE_ENV!=="production"&&!e&&S("onWatcherCleanup() was called when there was no active watcher to associate with.")}function ge(t,e,n=Wt){const{immediate:s,deep:r,once:i,scheduler:o,augmentJob:c,call:a}=n,d=l=>{(n.onWarn||S)("Invalid watch source: ",l,"A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.")},v=l=>r?l:w(l)||r===!1||r===0?D(l,1):D(l);let f,h,L,U,G=!1,J=!1;if(N(t)?(h=()=>t.value,G=w(t)):z(t)?(h=()=>v(t),G=!0):V(t)?(J=!0,G=t.some(l=>z(l)||w(l)),h=()=>t.map(l=>{if(N(l))return l.value;if(z(l))return v(l);if(wt(l))return a?a(l,2):l();process.env.NODE_ENV!=="production"&&d(l)})):wt(t)?e?h=a?()=>a(t,2):t:h=()=>{if(L){mt();try{L()}finally{Rt()}}const l=T;T=f;try{return a?a(t,3,[U]):t(U)}finally{T=l}}:(h=Ht,process.env.NODE_ENV!=="production"&&d(t)),e&&r){const l=h,b=r===!0?1/0:r;h=()=>D(l(),b)}const M=()=>{f.stop()};if(i&&e){const l=e;e=(...b)=>{l(...b),M()}}let x=J?new Array(t.length).fill(Z):Z;const W=l=>{if(!(!(f.flags&1)||!f.dirty&&!l))if(e){const b=f.run();if(r||G||(J?b.some((nt,Q)=>m(nt,x[Q])):m(b,x))){L&&L();const nt=T;T=f;try{const Q=[b,x===Z?void 0:J&&x[0]===Z?[]:x,U];x=b,a?a(e,3,Q):e(...Q)}finally{T=nt}}}else f.run()};return c&&c(W),f=new Gt(h),f.scheduler=o?()=>o(W,!1):W,U=l=>_e(l,!1,f),L=f.onStop=()=>{const l=tt.get(f);if(l){if(a)a(l,4);else for(const b of l)b();tt.delete(f)}},process.env.NODE_ENV!=="production"&&(f.onTrack=n.onTrack,f.onTrigger=n.onTrigger),e?s?W(!0):x=f.run():o?o(W.bind(null,!0),!0):f.run(),M.pause=f.pause.bind(f),M.resume=f.resume.bind(f),M.stop=M,M}function D(t,e=1/0,n){if(e<=0||!K(t)||t.__v_skip||(n=n||new Map,(n.get(t)||0)>=e))return t;if(n.set(t,e),e--,N(t))D(t.value,e,n);else if(V(t))for(let s=0;s<t.length;s++)D(t[s],e,n);else if(Ct(t)||P(t))t.forEach(s=>{D(s,e,n)});else if(Bt(t)){for(const s in t)D(t[s],e,n);for(const s of Object.getOwnPropertySymbols(t))Object.prototype.propertyIsEnumerable.call(t,s)&&D(t[s],e,n)}return t}class be{constructor(e){return e&&Object.assign(this,e),bt(this)}}const we={watch:ge};exports.Accessor=be;exports.reactiveUtils=we;
|