Comparing version 0.0.6 to 0.0.7
@@ -91,3 +91,2 @@ var __defProp = Object.defineProperty; | ||
const TO_LENS = Symbol(); | ||
const THROW_ON_COPY = Symbol(); | ||
let keyCounter = 0; | ||
@@ -129,9 +128,16 @@ const proxyLensKey = () => `$$ProxyLens(${keyCounter++})`; | ||
ownKeys(target) { | ||
return [...Reflect.ownKeys(target), THROW_ON_COPY]; | ||
return [...Reflect.ownKeys(target), "toLens", "toJSON"]; | ||
}, | ||
getOwnPropertyDescriptor(target, key) { | ||
if (key === THROW_ON_COPY) { | ||
throw new Error("Cannot copy a ProxyValue into a new value"); | ||
if (key === PROXY_VALUE) { | ||
return { | ||
enumerable: false, | ||
value: proxy | ||
}; | ||
} | ||
return Object.getOwnPropertyDescriptor(target, key); | ||
return { | ||
configurable: true, | ||
enumerable: true, | ||
value: proxy[key] | ||
}; | ||
}, | ||
@@ -179,9 +185,34 @@ set() { | ||
}, | ||
ownKeys() { | ||
return [THROW_ON_COPY]; | ||
ownKeys(target) { | ||
return [...Object.keys(cache), "$key", "use", TO_LENS]; | ||
}, | ||
getOwnPropertyDescriptor(target, key) { | ||
if (key === THROW_ON_COPY) { | ||
throw new Error("Cannot copy a ProxyLens into a new value"); | ||
if (key === "$key") { | ||
return { | ||
configurable: true, | ||
enumerable: true, | ||
value: proxy.$key | ||
}; | ||
} | ||
if (key === "use") { | ||
return { | ||
configurable: true, | ||
enumerable: true, | ||
value: proxy.use | ||
}; | ||
} | ||
if (key === TO_LENS) { | ||
return { | ||
configurable: true, | ||
enumerable: true, | ||
value: proxy[TO_LENS] | ||
}; | ||
} | ||
if (key in cache) { | ||
return { | ||
configurable: true, | ||
enumerable: true, | ||
value: cache[key] | ||
}; | ||
} | ||
return void 0; | ||
@@ -188,0 +219,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
var W=Object.defineProperty,Y=Object.defineProperties;var q=Object.getOwnPropertyDescriptors;var A=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable;var R=(c,f,l)=>f in c?W(c,f,{enumerable:!0,configurable:!0,writable:!0,value:l}):c[f]=l,O=(c,f)=>{for(var l in f||(f={}))z.call(f,l)&&R(c,l,f[l]);if(A)for(var l of A(f))X.call(f,l)&&R(c,l,f[l]);return c},N=(c,f)=>Y(c,q(f));(function(c,f){typeof exports=="object"&&typeof module!="undefined"?f(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],f):(c=typeof globalThis!="undefined"?globalThis:c||self,f(c.Concave={},c.React))})(this,function(c,f){"use strict";function l(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var i=l(f);const h=e=>Object.prototype.toString.call(e)==="[object Object]",_=e=>JSON.parse(JSON.stringify(e)),T=e=>h(e)?O({},e):Array.isArray(e)?[...e]:_(e),V=Object.freeze({get(e){return e},set(e,n){return n}}),v=()=>V,j=(e,n,r)=>({get(s){const t=e.get(s);return n(t)},set(s,t){const o=e.get(s);return e.set(s,r(o,t))}}),F=(e,n)=>j(e,r=>r[n],(r,s)=>{const t=T(r);return t[n]=s,t}),D=(e,n)=>r=>{const s=e.get(r),t=n(s);return Object.is(s,t)?r:e.set(r,n(s))},b=e=>{const n=new Set;let r=e;return{subscribe(s){return n.add(s),()=>n.delete(s)},getSnapshot(){return r},update(s){const t=s(r);Object.is(t,r)||(r=t,n.forEach(o=>o()))}}},g=Symbol(),C=Symbol(),S=Symbol();let I=0;const K=()=>`$$ProxyLens(${I++})`,$=e=>Array.isArray(e)||h(e),H=(e,n)=>{const r=e.createUse(e.lens);return s=>{const[t,o]=r(s);return[E(t,n),o]}},E=(e,n)=>{if(!$(e))return e;if(Reflect.has(e,g))return Reflect.get(e,g);let r;const s=new Proxy(e,{get(t,o){if(o===g)return s;if(o==="toJSON")return r!=null||(r=()=>t),r;if(o==="toLens")return n[C];const u=t[o],a=n[o];return E(u,a)},ownKeys(t){return[...Reflect.ownKeys(t),S]},getOwnPropertyDescriptor(t,o){if(o===S)throw new Error("Cannot copy a ProxyValue into a new value");return Object.getOwnPropertyDescriptor(t,o)},set(){throw new Error("Cannot set property on ProxyValue")},deleteProperty(){throw new Error("Cannot delete property on ProxyValue")}});return Object.defineProperty(e,g,{value:s,enumerable:!1}),s},w=e=>{const n={};let r,s,t;const o=new Proxy({},{get(u,a){if(a==="$key")return t!=null||(t=K()),t;if(a===C)return s!=null||(s=()=>o),s;if(a==="use")return r!=null||(r=H(e,o)),r;if(n[a]===void 0){const x=N(O({},e),{lens:F(e.lens,a)}),y=w(x);n[a]=y}return n[a]},ownKeys(){return[S]},getOwnPropertyDescriptor(u,a){if(a===S)throw new Error("Cannot copy a ProxyLens into a new value")},set(){throw new Error("Cannot set property on ProxyLens")},deleteProperty(){throw new Error("Cannot delete property on ProxyLens")}});return o},P=e=>{if(typeof e=="boolean")return(n,r)=>e?n!==r:!1;if(typeof e=="function")return e;if(Array.isArray(e)){const n=Object.fromEntries(e.map(r=>[r,!0]));return P(n)}return(n,r)=>{let s=!1,t=!1,o,u;if(Array.isArray(n)?(s=!0,o=n):o=[n],Array.isArray(r)?(t=!0,u=r):u=[r],t!==s||o.length!==u.length)return!0;for(let a=0;a<o.length;a++){const x=o[a],y=u[a];for(const p in e)if(P(e[p])(x[p],y[p]))return!0}return!1}},d=Symbol(),L=(e,n,r=!0)=>{const s=i.default.useRef(d),t=i.default.useRef(r),o=i.default.useRef(d);t.current!==r&&(o.current=d),t.current=r;const u=()=>{const y=s.current,p=n.get(e.getSnapshot());return Object.is(y,p)?y:y===d||(o.current===d&&(o.current=P(r)),o.current(y,p))?p:y},a=i.default.useSyncExternalStore(e.subscribe,u,u),x=i.default.useCallback(y=>e.update(D(n,y)),[e]);return s.current=a,[a,x]},m=Symbol(),G=()=>{const e=i.default.createContext(m);e.displayName="Lens(ExternalStoreContext)";const n=t=>o=>{const u=i.default.useContext(e);if(u===m)throw new Error("Cannot call `lens.use()` in a component outside of <LensProvider />");return L(u,t,o)},r=w({lens:v(),createUse:n}),s=t=>{const o=i.default.useRef();o.current||(o.current=b(t.value));const u=o.current;return i.default.useEffect(()=>{u.getSnapshot()!==t.value&&u.update(()=>t.value)},[t.value]),i.default.useEffect(()=>u.subscribe(()=>t.onChange(u.getSnapshot())),[t.onChange]),i.default.createElement(e.Provider,{value:u},t.children)};return s.displayName="Lens(Provider)",[r,s]},J=e=>{const n=b(e);return[w({lens:v(),createUse:t=>o=>L(n,t,o)}),{get current(){return n.getSnapshot()},set current(t){n.update(()=>t)}}]};c.stateful=J,c.stateless=G,Object.defineProperty(c,"__esModule",{value:!0}),c[Symbol.toStringTag]="Module"}); | ||
var M=Object.defineProperty,q=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var L=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable;var A=(a,l,f)=>l in a?M(a,l,{enumerable:!0,configurable:!0,writable:!0,value:f}):a[l]=f,h=(a,l)=>{for(var f in l||(l={}))W.call(l,f)&&A(a,f,l[f]);if(L)for(var f of L(l))X.call(l,f)&&A(a,f,l[f]);return a},R=(a,l)=>q(a,z(l));(function(a,l){typeof exports=="object"&&typeof module!="undefined"?l(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],l):(a=typeof globalThis!="undefined"?globalThis:a||self,l(a.Concave={},a.React))})(this,function(a,l){"use strict";function f(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var i=f(l);const m=e=>Object.prototype.toString.call(e)==="[object Object]",N=e=>JSON.parse(JSON.stringify(e)),_=e=>m(e)?h({},e):Array.isArray(e)?[...e]:N(e),T=Object.freeze({get(e){return e},set(e,r){return r}}),O=()=>T,V=(e,r,n)=>({get(o){const t=e.get(o);return r(t)},set(o,t){const u=e.get(o);return e.set(o,n(u,t))}}),$=(e,r)=>V(e,n=>n[r],(n,o)=>{const t=_(n);return t[r]=o,t}),j=(e,r)=>n=>{const o=e.get(n),t=r(o);return Object.is(o,t)?n:e.set(n,r(o))},P=e=>{const r=new Set;let n=e;return{subscribe(o){return r.add(o),()=>r.delete(o)},getSnapshot(){return n},update(o){const t=o(n);Object.is(t,n)||(n=t,r.forEach(u=>u()))}}},p=Symbol(),g=Symbol();let F=0;const I=()=>`$$ProxyLens(${F++})`,K=e=>Array.isArray(e)||m(e),D=(e,r)=>{const n=e.createUse(e.lens);return o=>{const[t,u]=n(o);return[w(t,r),u]}},w=(e,r)=>{if(!K(e))return e;if(Reflect.has(e,p))return Reflect.get(e,p);let n;const o=new Proxy(e,{get(t,u){if(u===p)return o;if(u==="toJSON")return n!=null||(n=()=>t),n;if(u==="toLens")return r[g];const c=t[u],s=r[u];return w(c,s)},ownKeys(t){return[...Reflect.ownKeys(t),"toLens","toJSON"]},getOwnPropertyDescriptor(t,u){return u===p?{enumerable:!1,value:o}:{configurable:!0,enumerable:!0,value:o[u]}},set(){throw new Error("Cannot set property on ProxyValue")},deleteProperty(){throw new Error("Cannot delete property on ProxyValue")}});return Object.defineProperty(e,p,{value:o,enumerable:!1}),o},S=e=>{const r={};let n,o,t;const u=new Proxy({},{get(c,s){if(s==="$key")return t!=null||(t=I()),t;if(s===g)return o!=null||(o=()=>u),o;if(s==="use")return n!=null||(n=D(e,u)),n;if(r[s]===void 0){const b=R(h({},e),{lens:$(e.lens,s)}),y=S(b);r[s]=y}return r[s]},ownKeys(c){return[...Object.keys(r),"$key","use",g]},getOwnPropertyDescriptor(c,s){if(s==="$key")return{configurable:!0,enumerable:!0,value:u.$key};if(s==="use")return{configurable:!0,enumerable:!0,value:u.use};if(s===g)return{configurable:!0,enumerable:!0,value:u[g]};if(s in r)return{configurable:!0,enumerable:!0,value:r[s]}},set(){throw new Error("Cannot set property on ProxyLens")},deleteProperty(){throw new Error("Cannot delete property on ProxyLens")}});return u},v=e=>{if(typeof e=="boolean")return(r,n)=>e?r!==n:!1;if(typeof e=="function")return e;if(Array.isArray(e)){const r=Object.fromEntries(e.map(n=>[n,!0]));return v(r)}return(r,n)=>{let o=!1,t=!1,u,c;if(Array.isArray(r)?(o=!0,u=r):u=[r],Array.isArray(n)?(t=!0,c=n):c=[n],t!==o||u.length!==c.length)return!0;for(let s=0;s<u.length;s++){const b=u[s],y=c[s];for(const d in e)if(v(e[d])(b[d],y[d]))return!0}return!1}},x=Symbol(),C=(e,r,n=!0)=>{const o=i.default.useRef(x),t=i.default.useRef(n),u=i.default.useRef(x);t.current!==n&&(u.current=x),t.current=n;const c=()=>{const y=o.current,d=r.get(e.getSnapshot());return Object.is(y,d)?y:y===x||(u.current===x&&(u.current=v(n)),u.current(y,d))?d:y},s=i.default.useSyncExternalStore(e.subscribe,c,c),b=i.default.useCallback(y=>e.update(j(r,y)),[e]);return o.current=s,[s,b]},E=Symbol(),J=()=>{const e=i.default.createContext(E);e.displayName="Lens(ExternalStoreContext)";const r=t=>u=>{const c=i.default.useContext(e);if(c===E)throw new Error("Cannot call `lens.use()` in a component outside of <LensProvider />");return C(c,t,u)},n=S({lens:O(),createUse:r}),o=t=>{const u=i.default.useRef();u.current||(u.current=P(t.value));const c=u.current;return i.default.useEffect(()=>{c.getSnapshot()!==t.value&&c.update(()=>t.value)},[t.value]),i.default.useEffect(()=>c.subscribe(()=>t.onChange(c.getSnapshot())),[t.onChange]),i.default.createElement(e.Provider,{value:c},t.children)};return o.displayName="Lens(Provider)",[n,o]},G=e=>{const r=P(e);return[S({lens:O(),createUse:t=>u=>C(r,t,u)}),{get current(){return r.getSnapshot()},set current(t){r.update(()=>t)}}]};a.stateful=G,a.stateless=J,Object.defineProperty(a,"__esModule",{value:!0}),a[Symbol.toStringTag]="Module"}); | ||
//# sourceMappingURL=concave.umd.js.map |
{ | ||
"name": "concave", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "A Lens-like interface for state management in React", | ||
@@ -5,0 +5,0 @@ "main": "dist/concave.umd.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
484
29189