vref 0.1.4 → 0.1.6

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 CHANGED
@@ -1,29 +1,33 @@
1
1
  # VRef
2
2
 
3
- A tiny library to track variable's updates.
4
- Designed to be **low-level** and **predictable**.
3
+ A Tiny Reactive library to track and respond to changes in variables, providing predictable low-level reactivity.
5
4
 
6
5
  ---
7
6
 
8
- ### Basic usage
7
+ ### Usage
9
8
 
10
9
  ```ts
11
10
  import ref from 'vref';
12
11
 
13
- const count = ref(0, e => console.log('Changed:', e.value));
12
+ // Primitive value
13
+ const count = ref(0, (evt) => {
14
+ console.log('Changed:', evt.value);
15
+ });
14
16
 
15
17
  count.value = 1;
16
18
  count.value++;
19
+
17
20
  console.log(count.value); // 2
18
- ```
19
21
 
20
- ```ts
21
- const user = ref({ name: 'John', age: 25 }, e => console.log(e));
22
+ // Object value
23
+ const user = ref({ name: 'John', age: 25 }, (evt) => {
24
+ console.log('Changed:', evt);
25
+ });
22
26
 
23
- user.value.age = 26; // reactive
24
- user.value.name = 'Doe'; // reactive
27
+ user.value.age = 26; // triggers onchange
28
+ user.value.name = 'Doe'; // triggers onchange
25
29
  ```
26
30
 
27
31
  ---
28
32
 
29
- Simple. Reactive. Proxy-powered.
33
+ Low-Level. Simple. Reactive.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t={Get:"get",Set:"set",Add:"add",Has:"has",Delete:"delete",Clear:"clear",ForbiddenKeys:new Set(["__proto__","constructor","prototype"])},e=Symbol("is_proxy"),r=Symbol("raw_object"),n=new Set(["copyWithin","fill","push","reverse","unshift"]),a=new Set(["concat","flat","slice","toReversed","toSpliced","with"]),i=new Set(["every","findIndex","findLastIndex","flatMap","forEach","map","reduce","reduceRight","some"]),o=new Set(["entries","keys","values",Symbol.iterator]),s=new Set(["includes","indexOf","lastIndexOf"]),c=new Set(["at"]),u=new Set(["filter","find","findLast","pop","shift","sort","splice","toSorted"]),l=new Set(["copyWithin","fill","reverse","set","sort"]),f=new Set(["forEach"]),d=new Set(["forEach"]);function h(e){return t.ForbiddenKeys.has(e)}function p(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function y(t){return function(t){return"object"==typeof t&&null!==t}(t)||function(t){return Array.isArray(t)||p(t)}(t)}function v(t){return t[e]??!1}function g(t){return y(t)&&v(t)}function H(t){return t instanceof Map||t instanceof WeakMap}function S(t){return t instanceof Set||t instanceof WeakSet}function w(t){return t[r]}function b(t){return g(t)?w(t):t}function A(...t){const[e]=t;return y(e)?K(...t):e}function k(t){return t.map(t=>b(t))}function O(t,e,r){return t.map(t=>A(t,e,r,!1))}function m(t,e,...r){if(r.length>0){const[n,...a]=r;if("function"==typeof n){function i(...r){const a=r.map(r=>A(r,t,e));return n.apply(this,a)}return[i,...a]}}return r}function j(t,e,r,...n){const a=e.has(this)?k(n):n;return t[r].apply(this,a)}function x(t,e,r,n,...a){const i=e.get(this),o=i?k(a):a,s=t[r].apply(this,o);return i&&n({target:i,action:r,key:void 0,value:a,prevValue:void 0}),s}function V(t,e,r,...n){const a=e.get(this),[i]=n,o=a?b(i):i;return t.has.call(this,o)||(t.add.call(this,o),a&&r({target:a,action:"add",key:i,value:i,prevValue:void 0})),a??this}function P(t,e,r,...n){const a=e.get(this),[i]=n,o=a?b(i):i,s=function(t,e){return t instanceof WeakMap?t.get(e):t.has(e)?e:void 0}(this,o),c=t.delete.call(this,o);return c&&a&&r({target:a,action:"delete",key:i,value:void 0,prevValue:s}),c}function R(t,e,r,...n){const a=e.has(this),[i]=n,o=a?b(i):i,s=t.get.call(this,o);return a?A(s,e,r):s}function M(t,e,...r){const n=e.has(this),[a]=r,i=n?b(a):a;return t.has.call(this,i)}function _(t,e,r,...n){const a=e.get(this),[i,o]=n,s=a?b(i):i,c=a?b(o):o,u=t.get.call(this,s);return Object.is(c,u)||(t.set.call(this,s,c),a&&r({target:a,action:"set",key:i,value:o,prevValue:u})),a??this}function W(t,e,r){if(this.size>0){const n=e.get(this);t.clear.call(this),n&&r({target:n,action:"clear",key:void 0,value:void 0,prevValue:void 0})}}function E(t,e,r,...n){const a=v(this)||e.has(this)?k(n):n;return t[r].apply(this,a)}function L(t,e,r,n,...a){const i=e.has(this)?m(e,n,...a):a;return t[r].apply(this,i)}function D(t,e,r,n){const a=e.get(this),i=t[r].call(this);return a?function(t,...e){const[r,n,a,i]=e,o=Array.isArray(r),s="entries"===a||H(r)&&a===Symbol.iterator,c={next(e){const r=b(this===c?t:this),a=t.next.call(r,e);if(!a.done)if(s)if(o){const[,t]=a.value;a.value[1]=A(t,n,i)}else a.value=a.value.map(t=>A(t,n,i));else a.value=A(a.value,n,i);return a},[Symbol.iterator](){return b(this)}};return c}(i,this,e,r,n):i}function I(t,e,r,n,...a){const i=e.has(this),o=i?k(a):a,s=t[r].apply(this,o);return i?O(s,e,n):s}function C(t,e,r,n,...a){const i=e.has(this),o=i?k(a):a,s=t[r].apply(this,o);return i?A(s,e,n):s}function F(t,e,r,n,...a){const i=e.get(this);let o;switch(r){case"filter":case"find":case"findLast":case"sort":case"toSorted":const s=i?m(e,n,...a):a;switch(o=t[r].apply(this,s),r){case"filter":case"toSorted":return i?O(o,e,n):o;case"find":case"findLast":return i?A(o,e,n):o;case"sort":return i&&n({target:i,action:"sort",key:void 0,value:a,prevValue:void 0}),i??this}case"pop":case"shift":case"splice":const c=i?k(a):a;switch(o=t[r].apply(this,c),i&&n({target:i,action:r,key:void 0,value:a,prevValue:void 0}),r){case"pop":case"shift":return i?A(o,e,n,!1):o;case"splice":return i?O(o,e,n):o}}}function G(t,...e){return function(...r){const[n,a]=e;let i;var o;return o=n,i="[object Object]"!==Object.prototype.toString.call(o)||Object.getPrototypeOf(o)!==Object.prototype&&!o.constructor?b(this):this,function(t,e){g(t)&&e.set(w(t),t)}(this,a),t.apply(i,e.concat(r))}}function K(g,w,b,A){if(v(g))return g;const k=w.get(g);if(k)return k;let O=!1;const m=new Proxy(g,{get(v,A,k){if(A===e)return!0;if(A===r)return g;let O;try{O=Reflect.get(v,A,k)}catch{O=Reflect.get(v,A)}if(!h(A)&&void 0!==O){if(y(O))return K(O,w,b);if("function"==typeof O){const e=function(t,e,r,n){return{conflictArrayHandler:G(F,t,r,e,n),mutationArrayHandler:G(x,t,r,e,n),producerArrayHandler:G(I,t,r,e,n),iterationHandler:G(L,t,r,e,n),iteratorHandler:G(D,t,r,e,n),lookupArrayHandler:G(j,t,r,e),pickingArrayHandler:G(C,t,r,e,n),getHandler:G(R,t,r,n),setHandler:G(_,t,r,n),addHandler:G(V,t,r,n),hasHandler:G(M,t,r),deleteHandler:G(P,t,r,n),clearHandler:G(W,t,r,n),defaultHandler:G(E,t,r,e)}}(v,A,w,b);if(Array.isArray(v)){if(u.has(A))return e.conflictArrayHandler;if(n.has(A))return e.mutationArrayHandler;if(a.has(A))return e.producerArrayHandler;if(i.has(A))return e.iterationHandler;if(o.has(A))return e.iteratorHandler;if(s.has(A))return e.lookupArrayHandler;if(c.has(A))return e.pickingArrayHandler}if(p(v)&&l.has(A))return e.mutationArrayHandler;if(H(v)){if(A===t.Get)return e.getHandler;if(A===t.Set)return e.setHandler}if(S(v)&&A===t.Add)return e.addHandler;if(v instanceof Map&&f.has(A)||v instanceof Set&&d.has(A))return e.iterationHandler;if(function(t){return t instanceof Map||t instanceof Set}(v)){if(A===t.Clear)return e.clearHandler;if(o.has(A))return e.iteratorHandler}if(function(t){return H(t)||S(t)}(v)){if(A===t.Has)return e.hasHandler;if(A===t.Delete)return e.deleteHandler}return e.defaultHandler}}return O},set(t,e,r,n){if(h(e))return!0;const a=t[e];if(!Object.is(a,r)){O=!0;const i=Reflect.set(t,e,r,n);return O=!1,i&&b({target:m,action:"set",key:e,value:r,prevValue:a}),i}return!0},deleteProperty(t,e){if(h(e))return!0;if(Object.prototype.hasOwnProperty.call(t,e)){const r=t[e],n=Reflect.deleteProperty(t,e);return n&&b({target:m,action:"delete",key:e,value:void 0,prevValue:r}),n}return!0},defineProperty(t,e,r){if(h(e))return!0;const n=t[e],a=Reflect.defineProperty(t,e,r);if(!O&&a){const t=r.value;Object.is(n,t)||b({target:m,action:"define",key:e,value:t,prevValue:n})}return a},setPrototypeOf:()=>!0});return(A??1)&&w.set(g,m),m}exports.default=function(t,e,r){const n=r?.cache??new WeakMap;return K(Object.preventExtensions({value:t}),n,e)},exports.getRaw=b,exports.isRef=g;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e={Get:"get",Set:"set",Add:"add",Has:"has",Delete:"delete",Clear:"clear",ReduceKeys:new Set(["reduce","reduceRight"]),ForbiddenKeys:new Set(["__proto__","constructor","prototype"])},t=Symbol("is_proxy"),r=Symbol("raw_object"),n=Symbol("parents"),i=new Set(["copyWithin","fill","push","reverse","unshift"]),a=new Set(["concat","flat","slice","toReversed","toSpliced","with"]),o=new Set(["every","findIndex","findLastIndex","flatMap","forEach","map","reduce","reduceRight","some"]),s=new Set(["entries","keys","values",Symbol.iterator]),c=new Set(["includes","indexOf","lastIndexOf"]),u=new Set(["at"]),l=new Set(["filter","find","findLast","pop","shift","sort","splice","toSorted"]),f=new Set(["copyWithin","fill","reverse","set","sort"]),d=new Set(["forEach"]),p=new Set(["forEach"]);function h(t){return e.ForbiddenKeys.has(t)}function y(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function v(e){return function(e){return"object"==typeof e&&null!==e}(e)||function(e){return Array.isArray(e)||y(e)}(e)}function g(e){return e[t]??!1}function H(e){return v(e)&&g(e)}function S(e){return e instanceof Map||e instanceof WeakMap}function w(e){return e instanceof Set||e instanceof WeakSet}function b(e){return e[r]}function k(e){return H(e)?b(e):e}function A(...e){const[t]=e;return v(t)?z(...e):t}function O(e){return e.map(e=>k(e))}function m(e,t,r,n,i){return e.map(e=>A(e,t,r,n,i,!1))}function j(e,t,r,n,i,...a){const[o,...s]=a;if("function"==typeof o){function c(...a){const s=a.map(a=>A(a,e===a?void 0:t,r,n,i,!1));return o.apply(this,s)}return[c,...s]}return a}function x(e,t,r,...n){const i=t.has(this)?O(n):n;return e[r].apply(this,i)}function R(e,t,r,n,...i){const a=t.get(this),o=a?O(i):i,s=e[r].apply(this,o);return a&&n({target:a,action:r,key:void 0,value:i,prevValue:void 0}),s===this&&a?a:s}function V(e,t,r,...n){const i=t.get(this),[a]=n,o=i?k(a):a;return e.has.call(this,o)||(e.add.call(this,o),i&&r({target:i,action:"add",key:a,value:a,prevValue:void 0})),i??this}function P(e,t,r,...n){const i=t.get(this),[a]=n,o=i?k(a):a,s=function(e,t){return e instanceof WeakMap?e.get(t):e.has(t)?t:void 0}(this,o),c=e.delete.call(this,o);return c&&i&&r({target:i,action:"delete",key:a,value:void 0,prevValue:s}),c}function M(e,t,r,n,...i){const a=t.get(this),[o]=i,s=a?k(o):o,c=e.get.call(this,s);return a?A(c,a,t,r,n):c}function _(e,t,...r){const n=t.has(this),[i]=r,a=n?k(i):i;return e.has.call(this,a)}function W(e,t,r,...n){const i=t.get(this),[a,o]=n,s=i?k(a):a,c=i?k(o):o,u=e.get.call(this,s);return Object.is(c,u)||(e.set.call(this,s,c),i&&r({target:i,action:"set",key:a,value:o,prevValue:u})),i??this}function E(e,t,r){if(this.size>0){const n=t.get(this);e.clear.call(this),n&&r({target:n,action:"clear",key:void 0,value:void 0,prevValue:void 0})}}function K(e,t,r,...n){const i=g(this)||t.has(this)?O(n):n;return e[r].apply(this,i)}function L(t,r,n,i,a,...o){const s=r.get(this);let c;return c=s?function(t){return e.ReduceKeys.has(t)}(i)?function(e,t,r,n,i,...a){const[o,...s]=a;return[function(...a){const s=a.map((a,o)=>o>0?A(a,e===a?void 0:t,r,n,i,!1):a);return o.apply(this,s)},...s]}(this,s,r,n,a,...o):j(this,s,r,n,a,...o):o,t[i].apply(this,c)}function D(e,t,r,n,i){const a=t.get(this),o=e[n].call(this);return a?function(e,t,r,n,i,a,o){const s=Array.isArray(t),c="entries"===a||S(t)&&a===Symbol.iterator,u=Object.create(Object.getPrototypeOf(e));return u.next=function(t){const a=k(this===u?e:this),l=e.next.call(a,t);if(!l.done)if(c)if(s){const[,e]=l.value;l.value[1]=A(e,r,n,i,o,!1)}else l.value=l.value.map(e=>A(e,r,n,i,o,!1));else l.value=A(l.value,r,n,i,o,!1);return l},u[Symbol.iterator]=function(){return k(this)},u}(o,this,a,t,r,n,i):o}function I(e,t,r,n,i,...a){const o=t.get(this),s=o?O(a):a,c=e[n].apply(this,s);return o?m(c,o,t,r,i):c}function C(e,t,r,n,i,...a){const o=t.get(this),s=o?O(a):a,c=e[n].apply(this,s);return o?A(c,o,t,r,i):c}function F(e,t,r,n,i,...a){const o=t.get(this);let s;switch(n){case"filter":case"find":case"findLast":case"sort":case"toSorted":const c=o?j(this,o,t,r,i,...a):a;switch(s=e[n].apply(this,c),n){case"filter":case"toSorted":return o?m(s,o,t,r,i):s;case"find":case"findLast":return o?A(s,o,t,r,i):s;case"sort":return o&&i({target:o,action:"sort",key:void 0,value:a,prevValue:void 0}),o??this}case"pop":case"shift":case"splice":const u=o?O(a):a;switch(s=e[n].apply(this,u),o&&i({target:o,action:n,key:void 0,value:a,prevValue:void 0}),n){case"pop":case"shift":return o?A(s,o,t,r,i,!1):s;case"splice":return o?m(s,o,t,r,i):s}}}function G(e,...t){return function(...r){const[n,i]=t;let a;var o;return o=n,a="[object Object]"!==Object.prototype.toString.call(o)||Object.getPrototypeOf(o)!==Object.prototype&&!o.constructor?k(this):this,function(e,t){H(e)&&t.set(b(e),e)}(this,i),e.apply(a,t.concat(r))}}function z(H,b,k,A,O,m){if(g(H))return H;let j=A.get(H);b&&(j?j.add(b):(j=new Set([b]),A.set(H,j)));const B=k.get(H);if(B)return B;let q=!1;const J=new Proxy(H,{get(g,b,m){if(b===n)return j;if(b===t)return!0;if(b===r)return H;let B;try{B=Reflect.get(g,b,m)}catch{B=Reflect.get(g,b)}if(!h(b)&&void 0!==B){if(v(B))return z(B,J,k,A,O);if("function"==typeof B){const t=function(e,t,r,n,i){return{conflictArrayHandler:G(F,e,r,n,t,i),mutationArrayHandler:G(R,e,r,t,i),producerArrayHandler:G(I,e,r,n,t,i),iterationHandler:G(L,e,r,n,t,i),iteratorHandler:G(D,e,r,n,t,i),lookupArrayHandler:G(x,e,r,t),pickingArrayHandler:G(C,e,r,n,t,i),getHandler:G(M,e,r,n,i),setHandler:G(W,e,r,i),addHandler:G(V,e,r,i),hasHandler:G(_,e,r),deleteHandler:G(P,e,r,i),clearHandler:G(E,e,r,i),defaultHandler:G(K,e,r,t)}}(g,b,k,A,O);if(Array.isArray(g)){if(l.has(b))return t.conflictArrayHandler;if(i.has(b))return t.mutationArrayHandler;if(a.has(b))return t.producerArrayHandler;if(o.has(b))return t.iterationHandler;if(s.has(b))return t.iteratorHandler;if(c.has(b))return t.lookupArrayHandler;if(u.has(b))return t.pickingArrayHandler}if(y(g)&&f.has(b))return t.mutationArrayHandler;if(S(g)){if(b===e.Get)return t.getHandler;if(b===e.Set)return t.setHandler}if(w(g)&&b===e.Add)return t.addHandler;if(g instanceof Map&&d.has(b)||g instanceof Set&&p.has(b))return t.iterationHandler;if(function(e){return e instanceof Map||e instanceof Set}(g)){if(b===e.Clear)return t.clearHandler;if(s.has(b))return t.iteratorHandler}if(function(e){return S(e)||w(e)}(g)){if(b===e.Has)return t.hasHandler;if(b===e.Delete)return t.deleteHandler}return t.defaultHandler}}return B},set(e,t,r,n){if(h(t))return!0;const i=e[t];if(!Object.is(i,r)){q=!0;const a=Reflect.set(e,t,r,n);return q=!1,a&&O({target:J,action:"set",key:t,value:r,prevValue:i}),a}return!0},deleteProperty(e,t){if(h(t))return!0;if(Object.prototype.hasOwnProperty.call(e,t)){const r=e[t],n=Reflect.deleteProperty(e,t);return n&&O({target:J,action:"delete",key:t,value:void 0,prevValue:r}),n}return!0},defineProperty(e,t,r){if(h(t))return!0;const n=e[t],i=Reflect.defineProperty(e,t,r);if(!q&&i){const e=r.value;Object.is(n,e)||O({target:J,action:"define",key:t,value:e,prevValue:n})}return i},setPrototypeOf:()=>!0});return(m??1)&&k.set(H,J),J}exports.default=function(e,t,r){const n=r?.cache??new WeakMap,i=r?.cacheParents??new WeakMap;return z(Object.preventExtensions({value:e}),void 0,n,i,t)},exports.getRaw=k,exports.isRef=H;
package/dist/index.d.ts CHANGED
@@ -24,18 +24,30 @@ type OnChangeHandler = (event: ChangeEvent) => void;
24
24
  */
25
25
  type RefOptions = {
26
26
  /**
27
- * Optional cache used to store mappings of raw objects to their corresponding proxies.
28
- *
29
- * This ensures that the same object reference always returns the same proxy,
30
- * preserving identity across repeated accesses (e.g., `obj.a === obj.a` remains true).
31
- *
32
- * Normally, this cache is automatically managed internally by the reactive system.
33
- * You can provide a custom WeakMap if you want multiple refs to share the same
34
- * reactivity graph or maintain consistent proxies across different refs.
35
- *
36
- * ⚠️ Note: Passing an invalid or reused cache may cause unexpected proxy behavior.
37
- */
27
+ * Optional cache used to store mappings of raw objects to their corresponding proxies.
28
+ *
29
+ * This ensures that the same object reference always returns the same proxy,
30
+ * preserving identity across repeated accesses (e.g., `obj.a === obj.a` remains true).
31
+ *
32
+ * Normally, this cache is automatically managed internally by the reactive system.
33
+ * You can provide a custom WeakMap if you want multiple refs to share the same
34
+ * reactivity graph or maintain consistent proxies across different refs.
35
+ *
36
+ * ⚠️ Note: Passing an invalid or reused cache may cause unexpected proxy behavior.
37
+ */
38
38
  cache?: WeakMap<object, object>;
39
+ /**
40
+ * Optional cache used to track the direct parent proxies of each raw object.
41
+ *
42
+ * Stores a mapping where the key is a raw object and the value is a Set of
43
+ * its immediate proxy parents (one level up in the object graph).
44
+ *
45
+ * Normally, this cache is internally managed. You can provide your own
46
+ * WeakMap if you want multiple refs to share the same parent-tracking graph.
47
+ *
48
+ * ⚠️ Note: Passing an invalid or reused cache may cause unexpected proxy behavior.
49
+ */
50
+ cacheParents?: WeakMap<object, Set<object>>;
39
51
  };
40
52
  /**
41
53
  * A reactive reference object.
@@ -56,6 +68,7 @@ type Ref<T> = {
56
68
  * - `value`: the reactive value.
57
69
  * - `onchange`: callback triggered on every change.
58
70
  * - `options.cache`: optional WeakMap for shared proxy identity.
71
+ * - `options.cacheParents`: optional WeakMap for parents proxy.
59
72
  *
60
73
  * Example:
61
74
  * ```ts
@@ -65,12 +78,31 @@ type Ref<T> = {
65
78
  *
66
79
  * @param initial Initial value.
67
80
  * @param onchange Callback that receives ChangeEvent on every change.
68
- * @param options Optional RefOptions (only `cache` is used by ref).
81
+ * @param options Optional RefOptions for proxy identity (`cache`) and parent tracking (`cacheParents`).
69
82
  * @returns A reactive Ref object.
70
83
  */
71
84
  declare function ref<T>(initial: T, onchange: OnChangeHandler, options?: RefOptions): Ref<T>;
72
85
 
86
+ /**
87
+ * Safely checks whether a value is a reactive proxy.
88
+ *
89
+ * - Returns `true` only if:
90
+ * 1. The value is proxiable (object, array, etc.),
91
+ * 2. And it is actually a proxy created by the reactive system.
92
+ *
93
+ * @param value Any value to test.
94
+ * @returns `true` if the value is a valid reactive proxy, otherwise `false`.
95
+ */
73
96
  declare function isProxyTry(value: any): boolean;
97
+ /**
98
+ * Safely retrieves the raw (unproxied) value.
99
+ *
100
+ * - If `value` is a proxy created by the reactive system, it returns its original raw target.
101
+ * - If `value` is not a proxy, it simply returns the input as-is.
102
+ *
103
+ * @param value Any value that may or may not be a proxy.
104
+ * @returns The raw underlying value if proxied, otherwise the original value.
105
+ */
74
106
  declare function getRawTry(value: any): any;
75
107
 
76
108
  export { ref as default, getRawTry as getRaw, isProxyTry as isRef };
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
1
- const t={Get:"get",Set:"set",Add:"add",Has:"has",Delete:"delete",Clear:"clear",ForbiddenKeys:new Set(["__proto__","constructor","prototype"])},e=Symbol("is_proxy"),r=Symbol("raw_object"),n=new Set(["copyWithin","fill","push","reverse","unshift"]),a=new Set(["concat","flat","slice","toReversed","toSpliced","with"]),i=new Set(["every","findIndex","findLastIndex","flatMap","forEach","map","reduce","reduceRight","some"]),s=new Set(["entries","keys","values",Symbol.iterator]),o=new Set(["includes","indexOf","lastIndexOf"]),c=new Set(["at"]),u=new Set(["filter","find","findLast","pop","shift","sort","splice","toSorted"]),l=new Set(["copyWithin","fill","reverse","set","sort"]),f=new Set(["forEach"]),d=new Set(["forEach"]);function h(e){return t.ForbiddenKeys.has(e)}function p(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function y(t){return function(t){return"object"==typeof t&&null!==t}(t)||function(t){return Array.isArray(t)||p(t)}(t)}function v(t){return t[e]??!1}function g(t){return y(t)&&v(t)}function H(t){return t instanceof Map||t instanceof WeakMap}function S(t){return t instanceof Set||t instanceof WeakSet}function w(t){return t[r]}function A(t){return g(t)?w(t):t}function b(...t){const[e]=t;return y(e)?K(...t):e}function k(t){return t.map(t=>A(t))}function m(t,e,r){return t.map(t=>b(t,e,r,!1))}function O(t,e,...r){if(r.length>0){const[n,...a]=r;if("function"==typeof n){function i(...r){const a=r.map(r=>b(r,t,e));return n.apply(this,a)}return[i,...a]}}return r}function j(t,e,r,...n){const a=e.has(this)?k(n):n;return t[r].apply(this,a)}function V(t,e,r,n,...a){const i=e.get(this),s=i?k(a):a,o=t[r].apply(this,s);return i&&n({target:i,action:r,key:void 0,value:a,prevValue:void 0}),o}function x(t,e,r,...n){const a=e.get(this),[i]=n,s=a?A(i):i;return t.has.call(this,s)||(t.add.call(this,s),a&&r({target:a,action:"add",key:i,value:i,prevValue:void 0})),a??this}function R(t,e,r,...n){const a=e.get(this),[i]=n,s=a?A(i):i,o=function(t,e){return t instanceof WeakMap?t.get(e):t.has(e)?e:void 0}(this,s),c=t.delete.call(this,s);return c&&a&&r({target:a,action:"delete",key:i,value:void 0,prevValue:o}),c}function P(t,e,r,...n){const a=e.has(this),[i]=n,s=a?A(i):i,o=t.get.call(this,s);return a?b(o,e,r):o}function M(t,e,...r){const n=e.has(this),[a]=r,i=n?A(a):a;return t.has.call(this,i)}function W(t,e,r,...n){const a=e.get(this),[i,s]=n,o=a?A(i):i,c=a?A(s):s,u=t.get.call(this,o);return Object.is(c,u)||(t.set.call(this,o,c),a&&r({target:a,action:"set",key:i,value:s,prevValue:u})),a??this}function _(t,e,r){if(this.size>0){const n=e.get(this);t.clear.call(this),n&&r({target:n,action:"clear",key:void 0,value:void 0,prevValue:void 0})}}function E(t,e,r,...n){const a=v(this)||e.has(this)?k(n):n;return t[r].apply(this,a)}function L(t,e,r,n,...a){const i=e.has(this)?O(e,n,...a):a;return t[r].apply(this,i)}function D(t,e,r,n){const a=e.get(this),i=t[r].call(this);return a?function(t,...e){const[r,n,a,i]=e,s=Array.isArray(r),o="entries"===a||H(r)&&a===Symbol.iterator,c={next(e){const r=A(this===c?t:this),a=t.next.call(r,e);if(!a.done)if(o)if(s){const[,t]=a.value;a.value[1]=b(t,n,i)}else a.value=a.value.map(t=>b(t,n,i));else a.value=b(a.value,n,i);return a},[Symbol.iterator](){return A(this)}};return c}(i,this,e,r,n):i}function I(t,e,r,n,...a){const i=e.has(this),s=i?k(a):a,o=t[r].apply(this,s);return i?m(o,e,n):o}function C(t,e,r,n,...a){const i=e.has(this),s=i?k(a):a,o=t[r].apply(this,s);return i?b(o,e,n):o}function F(t,e,r,n,...a){const i=e.get(this);let s;switch(r){case"filter":case"find":case"findLast":case"sort":case"toSorted":const o=i?O(e,n,...a):a;switch(s=t[r].apply(this,o),r){case"filter":case"toSorted":return i?m(s,e,n):s;case"find":case"findLast":return i?b(s,e,n):s;case"sort":return i&&n({target:i,action:"sort",key:void 0,value:a,prevValue:void 0}),i??this}case"pop":case"shift":case"splice":const c=i?k(a):a;switch(s=t[r].apply(this,c),i&&n({target:i,action:r,key:void 0,value:a,prevValue:void 0}),r){case"pop":case"shift":return i?b(s,e,n,!1):s;case"splice":return i?m(s,e,n):s}}}function G(t,...e){return function(...r){const[n,a]=e;let i;var s;return s=n,i="[object Object]"!==Object.prototype.toString.call(s)||Object.getPrototypeOf(s)!==Object.prototype&&!s.constructor?A(this):this,function(t,e){g(t)&&e.set(w(t),t)}(this,a),t.apply(i,e.concat(r))}}function K(g,w,A,b){if(v(g))return g;const k=w.get(g);if(k)return k;let m=!1;const O=new Proxy(g,{get(v,b,k){if(b===e)return!0;if(b===r)return g;let m;try{m=Reflect.get(v,b,k)}catch{m=Reflect.get(v,b)}if(!h(b)&&void 0!==m){if(y(m))return K(m,w,A);if("function"==typeof m){const e=function(t,e,r,n){return{conflictArrayHandler:G(F,t,r,e,n),mutationArrayHandler:G(V,t,r,e,n),producerArrayHandler:G(I,t,r,e,n),iterationHandler:G(L,t,r,e,n),iteratorHandler:G(D,t,r,e,n),lookupArrayHandler:G(j,t,r,e),pickingArrayHandler:G(C,t,r,e,n),getHandler:G(P,t,r,n),setHandler:G(W,t,r,n),addHandler:G(x,t,r,n),hasHandler:G(M,t,r),deleteHandler:G(R,t,r,n),clearHandler:G(_,t,r,n),defaultHandler:G(E,t,r,e)}}(v,b,w,A);if(Array.isArray(v)){if(u.has(b))return e.conflictArrayHandler;if(n.has(b))return e.mutationArrayHandler;if(a.has(b))return e.producerArrayHandler;if(i.has(b))return e.iterationHandler;if(s.has(b))return e.iteratorHandler;if(o.has(b))return e.lookupArrayHandler;if(c.has(b))return e.pickingArrayHandler}if(p(v)&&l.has(b))return e.mutationArrayHandler;if(H(v)){if(b===t.Get)return e.getHandler;if(b===t.Set)return e.setHandler}if(S(v)&&b===t.Add)return e.addHandler;if(v instanceof Map&&f.has(b)||v instanceof Set&&d.has(b))return e.iterationHandler;if(function(t){return t instanceof Map||t instanceof Set}(v)){if(b===t.Clear)return e.clearHandler;if(s.has(b))return e.iteratorHandler}if(function(t){return H(t)||S(t)}(v)){if(b===t.Has)return e.hasHandler;if(b===t.Delete)return e.deleteHandler}return e.defaultHandler}}return m},set(t,e,r,n){if(h(e))return!0;const a=t[e];if(!Object.is(a,r)){m=!0;const i=Reflect.set(t,e,r,n);return m=!1,i&&A({target:O,action:"set",key:e,value:r,prevValue:a}),i}return!0},deleteProperty(t,e){if(h(e))return!0;if(Object.prototype.hasOwnProperty.call(t,e)){const r=t[e],n=Reflect.deleteProperty(t,e);return n&&A({target:O,action:"delete",key:e,value:void 0,prevValue:r}),n}return!0},defineProperty(t,e,r){if(h(e))return!0;const n=t[e],a=Reflect.defineProperty(t,e,r);if(!m&&a){const t=r.value;Object.is(n,t)||A({target:O,action:"define",key:e,value:t,prevValue:n})}return a},setPrototypeOf:()=>!0});return(b??1)&&w.set(g,O),O}function z(t,e,r){const n=r?.cache??new WeakMap;return K(Object.preventExtensions({value:t}),n,e)}export{z as default,A as getRaw,g as isRef};
1
+ const t={Get:"get",Set:"set",Add:"add",Has:"has",Delete:"delete",Clear:"clear",ReduceKeys:new Set(["reduce","reduceRight"]),ForbiddenKeys:new Set(["__proto__","constructor","prototype"])},e=Symbol("is_proxy"),r=Symbol("raw_object"),n=Symbol("parents"),i=new Set(["copyWithin","fill","push","reverse","unshift"]),a=new Set(["concat","flat","slice","toReversed","toSpliced","with"]),o=new Set(["every","findIndex","findLastIndex","flatMap","forEach","map","reduce","reduceRight","some"]),s=new Set(["entries","keys","values",Symbol.iterator]),c=new Set(["includes","indexOf","lastIndexOf"]),u=new Set(["at"]),l=new Set(["filter","find","findLast","pop","shift","sort","splice","toSorted"]),f=new Set(["copyWithin","fill","reverse","set","sort"]),d=new Set(["forEach"]),h=new Set(["forEach"]);function p(e){return t.ForbiddenKeys.has(e)}function y(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function v(t){return function(t){return"object"==typeof t&&null!==t}(t)||function(t){return Array.isArray(t)||y(t)}(t)}function g(t){return t[e]??!1}function H(t){return v(t)&&g(t)}function S(t){return t instanceof Map||t instanceof WeakMap}function w(t){return t instanceof Set||t instanceof WeakSet}function b(t){return t[r]}function k(t){return H(t)?b(t):t}function A(...t){const[e]=t;return v(e)?z(...t):e}function O(t){return t.map(t=>k(t))}function m(t,e,r,n,i){return t.map(t=>A(t,e,r,n,i,!1))}function j(t,e,r,n,i,...a){const[o,...s]=a;if("function"==typeof o){function c(...a){const s=a.map(a=>A(a,t===a?void 0:e,r,n,i,!1));return o.apply(this,s)}return[c,...s]}return a}function R(t,e,r,...n){const i=e.has(this)?O(n):n;return t[r].apply(this,i)}function V(t,e,r,n,...i){const a=e.get(this),o=a?O(i):i,s=t[r].apply(this,o);return a&&n({target:a,action:r,key:void 0,value:i,prevValue:void 0}),s===this&&a?a:s}function x(t,e,r,...n){const i=e.get(this),[a]=n,o=i?k(a):a;return t.has.call(this,o)||(t.add.call(this,o),i&&r({target:i,action:"add",key:a,value:a,prevValue:void 0})),i??this}function P(t,e,r,...n){const i=e.get(this),[a]=n,o=i?k(a):a,s=function(t,e){return t instanceof WeakMap?t.get(e):t.has(e)?e:void 0}(this,o),c=t.delete.call(this,o);return c&&i&&r({target:i,action:"delete",key:a,value:void 0,prevValue:s}),c}function M(t,e,r,n,...i){const a=e.get(this),[o]=i,s=a?k(o):o,c=t.get.call(this,s);return a?A(c,a,e,r,n):c}function W(t,e,...r){const n=e.has(this),[i]=r,a=n?k(i):i;return t.has.call(this,a)}function _(t,e,r,...n){const i=e.get(this),[a,o]=n,s=i?k(a):a,c=i?k(o):o,u=t.get.call(this,s);return Object.is(c,u)||(t.set.call(this,s,c),i&&r({target:i,action:"set",key:a,value:o,prevValue:u})),i??this}function E(t,e,r){if(this.size>0){const n=e.get(this);t.clear.call(this),n&&r({target:n,action:"clear",key:void 0,value:void 0,prevValue:void 0})}}function K(t,e,r,...n){const i=g(this)||e.has(this)?O(n):n;return t[r].apply(this,i)}function L(e,r,n,i,a,...o){const s=r.get(this);let c;return c=s?function(e){return t.ReduceKeys.has(e)}(i)?function(t,e,r,n,i,...a){const[o,...s]=a;return[function(...a){const s=a.map((a,o)=>o>0?A(a,t===a?void 0:e,r,n,i,!1):a);return o.apply(this,s)},...s]}(this,s,r,n,a,...o):j(this,s,r,n,a,...o):o,e[i].apply(this,c)}function D(t,e,r,n,i){const a=e.get(this),o=t[n].call(this);return a?function(t,e,r,n,i,a,o){const s=Array.isArray(e),c="entries"===a||S(e)&&a===Symbol.iterator,u=Object.create(Object.getPrototypeOf(t));return u.next=function(e){const a=k(this===u?t:this),l=t.next.call(a,e);if(!l.done)if(c)if(s){const[,t]=l.value;l.value[1]=A(t,r,n,i,o,!1)}else l.value=l.value.map(t=>A(t,r,n,i,o,!1));else l.value=A(l.value,r,n,i,o,!1);return l},u[Symbol.iterator]=function(){return k(this)},u}(o,this,a,e,r,n,i):o}function I(t,e,r,n,i,...a){const o=e.get(this),s=o?O(a):a,c=t[n].apply(this,s);return o?m(c,o,e,r,i):c}function C(t,e,r,n,i,...a){const o=e.get(this),s=o?O(a):a,c=t[n].apply(this,s);return o?A(c,o,e,r,i):c}function F(t,e,r,n,i,...a){const o=e.get(this);let s;switch(n){case"filter":case"find":case"findLast":case"sort":case"toSorted":const c=o?j(this,o,e,r,i,...a):a;switch(s=t[n].apply(this,c),n){case"filter":case"toSorted":return o?m(s,o,e,r,i):s;case"find":case"findLast":return o?A(s,o,e,r,i):s;case"sort":return o&&i({target:o,action:"sort",key:void 0,value:a,prevValue:void 0}),o??this}case"pop":case"shift":case"splice":const u=o?O(a):a;switch(s=t[n].apply(this,u),o&&i({target:o,action:n,key:void 0,value:a,prevValue:void 0}),n){case"pop":case"shift":return o?A(s,o,e,r,i,!1):s;case"splice":return o?m(s,o,e,r,i):s}}}function G(t,...e){return function(...r){const[n,i]=e;let a;var o;return o=n,a="[object Object]"!==Object.prototype.toString.call(o)||Object.getPrototypeOf(o)!==Object.prototype&&!o.constructor?k(this):this,function(t,e){H(t)&&e.set(b(t),t)}(this,i),t.apply(a,e.concat(r))}}function z(H,b,k,A,O,m){if(g(H))return H;let j=A.get(H);b&&(j?j.add(b):(j=new Set([b]),A.set(H,j)));const B=k.get(H);if(B)return B;let q=!1;const J=new Proxy(H,{get(g,b,m){if(b===n)return j;if(b===e)return!0;if(b===r)return H;let B;try{B=Reflect.get(g,b,m)}catch{B=Reflect.get(g,b)}if(!p(b)&&void 0!==B){if(v(B))return z(B,J,k,A,O);if("function"==typeof B){const e=function(t,e,r,n,i){return{conflictArrayHandler:G(F,t,r,n,e,i),mutationArrayHandler:G(V,t,r,e,i),producerArrayHandler:G(I,t,r,n,e,i),iterationHandler:G(L,t,r,n,e,i),iteratorHandler:G(D,t,r,n,e,i),lookupArrayHandler:G(R,t,r,e),pickingArrayHandler:G(C,t,r,n,e,i),getHandler:G(M,t,r,n,i),setHandler:G(_,t,r,i),addHandler:G(x,t,r,i),hasHandler:G(W,t,r),deleteHandler:G(P,t,r,i),clearHandler:G(E,t,r,i),defaultHandler:G(K,t,r,e)}}(g,b,k,A,O);if(Array.isArray(g)){if(l.has(b))return e.conflictArrayHandler;if(i.has(b))return e.mutationArrayHandler;if(a.has(b))return e.producerArrayHandler;if(o.has(b))return e.iterationHandler;if(s.has(b))return e.iteratorHandler;if(c.has(b))return e.lookupArrayHandler;if(u.has(b))return e.pickingArrayHandler}if(y(g)&&f.has(b))return e.mutationArrayHandler;if(S(g)){if(b===t.Get)return e.getHandler;if(b===t.Set)return e.setHandler}if(w(g)&&b===t.Add)return e.addHandler;if(g instanceof Map&&d.has(b)||g instanceof Set&&h.has(b))return e.iterationHandler;if(function(t){return t instanceof Map||t instanceof Set}(g)){if(b===t.Clear)return e.clearHandler;if(s.has(b))return e.iteratorHandler}if(function(t){return S(t)||w(t)}(g)){if(b===t.Has)return e.hasHandler;if(b===t.Delete)return e.deleteHandler}return e.defaultHandler}}return B},set(t,e,r,n){if(p(e))return!0;const i=t[e];if(!Object.is(i,r)){q=!0;const a=Reflect.set(t,e,r,n);return q=!1,a&&O({target:J,action:"set",key:e,value:r,prevValue:i}),a}return!0},deleteProperty(t,e){if(p(e))return!0;if(Object.prototype.hasOwnProperty.call(t,e)){const r=t[e],n=Reflect.deleteProperty(t,e);return n&&O({target:J,action:"delete",key:e,value:void 0,prevValue:r}),n}return!0},defineProperty(t,e,r){if(p(e))return!0;const n=t[e],i=Reflect.defineProperty(t,e,r);if(!q&&i){const t=r.value;Object.is(n,t)||O({target:J,action:"define",key:e,value:t,prevValue:n})}return i},setPrototypeOf:()=>!0});return(m??1)&&k.set(H,J),J}function B(t,e,r){const n=r?.cache??new WeakMap,i=r?.cacheParents??new WeakMap;return z(Object.preventExtensions({value:t}),void 0,n,i,e)}export{B as default,k as getRaw,H as isRef};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vref",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "license": "MIT",
5
5
  "author": "John Soatra",
6
6
  "description": "A Javascript library for reactive state management.",