Comparing version 0.0.7 to 0.0.8-alpha1
@@ -91,2 +91,3 @@ var __defProp = Object.defineProperty; | ||
const TO_LENS = Symbol(); | ||
let showCopyLensWarning = false; | ||
let keyCounter = 0; | ||
@@ -137,7 +138,3 @@ const proxyLensKey = () => `$$ProxyLens(${keyCounter++})`; | ||
} | ||
return { | ||
configurable: true, | ||
enumerable: true, | ||
value: proxy[key] | ||
}; | ||
return { configurable: true, enumerable: true, value: proxy[key] }; | ||
}, | ||
@@ -211,2 +208,6 @@ set() { | ||
if (key in cache) { | ||
if (!showCopyLensWarning) { | ||
showCopyLensWarning = true; | ||
console.warn(`"%c${String(key)}" as a key on ProxyLens is only available because it has been previously accessed. If you are iterating through keys of this object via \`{ ...obj }\` or \`Object.assign({}, obj)\`, please consider an alternative approach.`, "color: red; font-weight: bold;"); | ||
} | ||
return { | ||
@@ -218,3 +219,2 @@ configurable: true, | ||
} | ||
return void 0; | ||
}, | ||
@@ -221,0 +221,0 @@ set() { |
@@ -1,2 +0,2 @@ | ||
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"}); | ||
var W=Object.defineProperty,q=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var A=Object.getOwnPropertySymbols;var X=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable;var R=(c,l,i)=>l in c?W(c,l,{enumerable:!0,configurable:!0,writable:!0,value:i}):c[l]=i,h=(c,l)=>{for(var i in l||(l={}))X.call(l,i)&&R(c,i,l[i]);if(A)for(var i of A(l))Y.call(l,i)&&R(c,i,l[i]);return c},N=(c,l)=>q(c,z(l));(function(c,l){typeof exports=="object"&&typeof module!="undefined"?l(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],l):(c=typeof globalThis!="undefined"?globalThis:c||self,l(c.Concave={},c.React))})(this,function(c,l){"use strict";function i(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var f=i(l);const w=e=>Object.prototype.toString.call(e)==="[object Object]",j=e=>JSON.parse(JSON.stringify(e)),_=e=>w(e)?h({},e):Array.isArray(e)?[...e]:j(e),$=Object.freeze({get(e){return e},set(e,r){return r}}),O=()=>$,T=(e,r,n)=>({get(s){const t=e.get(s);return r(t)},set(s,t){const o=e.get(s);return e.set(s,n(o,t))}}),V=(e,r)=>T(e,n=>n[r],(n,s)=>{const t=_(n);return t[r]=s,t}),F=(e,r)=>n=>{const s=e.get(n),t=r(s);return Object.is(s,t)?n:e.set(n,r(s))},P=e=>{const r=new Set;let n=e;return{subscribe(s){return r.add(s),()=>r.delete(s)},getSnapshot(){return n},update(s){const t=s(n);Object.is(t,n)||(n=t,r.forEach(o=>o()))}}},d=Symbol(),g=Symbol();let m=!1,I=0;const K=()=>`$$ProxyLens(${I++})`,D=e=>Array.isArray(e)||w(e),J=(e,r)=>{const n=e.createUse(e.lens);return s=>{const[t,o]=n(s);return[L(t,r),o]}},L=(e,r)=>{if(!D(e))return e;if(Reflect.has(e,d))return Reflect.get(e,d);let n;const s=new Proxy(e,{get(t,o){if(o===d)return s;if(o==="toJSON")return n!=null||(n=()=>t),n;if(o==="toLens")return r[g];const a=t[o],u=r[o];return L(a,u)},ownKeys(t){return[...Reflect.ownKeys(t),"toLens","toJSON"]},getOwnPropertyDescriptor(t,o){return o===d?{enumerable:!1,value:s}:{configurable:!0,enumerable:!0,value:s[o]}},set(){throw new Error("Cannot set property on ProxyValue")},deleteProperty(){throw new Error("Cannot delete property on ProxyValue")}});return Object.defineProperty(e,d,{value:s,enumerable:!1}),s},S=e=>{const r={};let n,s,t;const o=new Proxy({},{get(a,u){if(u==="$key")return t!=null||(t=K()),t;if(u===g)return s!=null||(s=()=>o),s;if(u==="use")return n!=null||(n=J(e,o)),n;if(r[u]===void 0){const x=N(h({},e),{lens:V(e.lens,u)}),y=S(x);r[u]=y}return r[u]},ownKeys(a){return[...Object.keys(r),"$key","use",g]},getOwnPropertyDescriptor(a,u){if(u==="$key")return{configurable:!0,enumerable:!0,value:o.$key};if(u==="use")return{configurable:!0,enumerable:!0,value:o.use};if(u===g)return{configurable:!0,enumerable:!0,value:o[g]};if(u in r)return m||(m=!0,console.warn(`"%c${String(u)}" as a key on ProxyLens is only available because it has been previously accessed. If you are iterating through keys of this object via \`{ ...obj }\` or \`Object.assign({}, obj)\`, please consider an alternative approach.`,"color: red; font-weight: bold;")),{configurable:!0,enumerable:!0,value:r[u]}},set(){throw new Error("Cannot set property on ProxyLens")},deleteProperty(){throw new Error("Cannot delete property on ProxyLens")}});return o},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 s=!1,t=!1,o,a;if(Array.isArray(r)?(s=!0,o=r):o=[r],Array.isArray(n)?(t=!0,a=n):a=[n],t!==s||o.length!==a.length)return!0;for(let u=0;u<o.length;u++){const x=o[u],y=a[u];for(const p in e)if(v(e[p])(x[p],y[p]))return!0}return!1}},b=Symbol(),C=(e,r,n=!0)=>{const s=f.default.useRef(b),t=f.default.useRef(n),o=f.default.useRef(b);t.current!==n&&(o.current=b),t.current=n;const a=()=>{const y=s.current,p=r.get(e.getSnapshot());return Object.is(y,p)?y:y===b||(o.current===b&&(o.current=v(n)),o.current(y,p))?p:y},u=f.default.useSyncExternalStore(e.subscribe,a,a),x=f.default.useCallback(y=>e.update(F(r,y)),[e]);return s.current=u,[u,x]},E=Symbol(),G=()=>{const e=f.default.createContext(E);e.displayName="Lens(ExternalStoreContext)";const r=t=>o=>{const a=f.default.useContext(e);if(a===E)throw new Error("Cannot call `lens.use()` in a component outside of <LensProvider />");return C(a,t,o)},n=S({lens:O(),createUse:r}),s=t=>{const o=f.default.useRef();o.current||(o.current=P(t.value));const a=o.current;return f.default.useEffect(()=>{a.getSnapshot()!==t.value&&a.update(()=>t.value)},[t.value]),f.default.useEffect(()=>a.subscribe(()=>t.onChange(a.getSnapshot())),[t.onChange]),f.default.createElement(e.Provider,{value:a},t.children)};return s.displayName="Lens(Provider)",[n,s]},H=e=>{const r=P(e);return[S({lens:O(),createUse:t=>o=>C(r,t,o)}),{get current(){return r.getSnapshot()},set current(t){r.update(()=>t)}}]};c.stateful=H,c.stateless=G,Object.defineProperty(c,"__esModule",{value:!0}),c[Symbol.toStringTag]="Module"}); | ||
//# sourceMappingURL=concave.umd.js.map |
{ | ||
"name": "concave", | ||
"version": "0.0.7", | ||
"version": "0.0.8-alpha1", | ||
"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
32874
485