vref 0.1.7 → 0.1.8
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 +8 -6
- package/dist/index.cjs.cjs +1 -1
- package/dist/index.esm.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,11 +7,11 @@ A Tiny Reactive library to track and respond to changes in variables, providing
|
|
|
7
7
|
### Usage
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
-
import ref from
|
|
10
|
+
import ref from "vref";
|
|
11
11
|
|
|
12
12
|
// Primitive value
|
|
13
13
|
const count = ref(0, (evt) => {
|
|
14
|
-
console.log(
|
|
14
|
+
console.log("Changed:", evt.value);
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
count.value = 1;
|
|
@@ -20,12 +20,14 @@ count.value++;
|
|
|
20
20
|
console.log(count.value); // 2
|
|
21
21
|
|
|
22
22
|
// Object value
|
|
23
|
-
const user = ref({ name:
|
|
24
|
-
console.log(
|
|
23
|
+
const { value: user } = ref({ name: "John", age: 25 }, (evt) => {
|
|
24
|
+
console.log("Changed:", evt);
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
user.
|
|
28
|
-
user.
|
|
27
|
+
user.name = "Doe"; // triggers onchange
|
|
28
|
+
user.age += 1; // triggers onchange
|
|
29
|
+
|
|
30
|
+
console.log(user); // { name: "Doe", age: 26 }
|
|
29
31
|
```
|
|
30
32
|
|
|
31
33
|
---
|
package/dist/index.cjs.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,a,o){return e.map(e=>A(e,r,n,i,a,o??t.includes(e)))}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));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)=>{if(o>0){const o=e===a?void 0:t,s=e.includes(a);return A(a,o,r,n,i,s)}return 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)}else l.value=l.value.map(e=>A(e,r,n,i,o));else l.value=A(l.value,r,n,i,o);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,e,o,t,r,i,"slice"===n||"toReversed"===n||void 0):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,e,o,t,r,i,!0):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,e,o,t,r,i,!1):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.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
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"]),h=new Set(["forEach"]);function p(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,a,o){return e.map(e=>A(e,r,n,i,a,o??t.includes(e)))}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));return o.apply(this,s)}return[c,...s]}return a}function R(e,t,r,...n){const i=t.has(this)?O(n):n;return e[r].apply(this,i)}function V(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 x(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 W(e,t,...r){const n=t.has(this),[i]=r,a=n?k(i):i;return e.has.call(this,a)}function _(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)=>{if(o>0){const o=e===a?void 0:t,s=e.includes(a);return A(a,o,r,n,i,s)}return 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)}else l.value=l.value.map(e=>A(e,r,n,i,o));else l.value=A(l.value,r,n,i,o);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,e,o,t,r,i,"slice"===n||"toReversed"===n||void 0):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,e,o,t,r,i,!0):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,e,o,t,r,i,!1):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(!p(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(V,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(R,e,r,t),pickingArrayHandler:G(C,e,r,n,t,i),getHandler:G(M,e,r,n,i),setHandler:G(_,e,r,i),addHandler:G(x,e,r,i),hasHandler:G(W,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&&h.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(p(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(p(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(p(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}function B(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)}export{B as default,k as getRaw,H as isRef};
|