Comparing version 0.0.10-alpha1 to 0.0.10-alpha2
@@ -20,3 +20,3 @@ var __defProp = Object.defineProperty; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
import React, { useDebugValue } from "react"; | ||
import React from "react"; | ||
const externalStore = (initialState) => { | ||
@@ -361,3 +361,2 @@ const listeners = new Set(); | ||
return function useStatelessLensState(keyPath, shouldUpdate) { | ||
useDebugValue(keyPath); | ||
const store = React.useContext(ExternalStoreContext); | ||
@@ -367,3 +366,6 @@ if (store === NOTHING) { | ||
} | ||
return useSyncExternalStoreWithLens(store, basic, shouldUpdate); | ||
const next = useSyncExternalStoreWithLens(store, basic, shouldUpdate); | ||
React.useDebugValue(`Key path: ${JSON.stringify(keyPath)}`); | ||
React.useDebugValue(`State: ${JSON.stringify(next[0])}`); | ||
return next; | ||
}; | ||
@@ -382,4 +384,6 @@ }); | ||
return function useStatefulLensState(keyPath, shouldUpdate) { | ||
useDebugValue(keyPath); | ||
return useSyncExternalStoreWithLens(store, basic, shouldUpdate); | ||
const next = useSyncExternalStoreWithLens(store, basic, shouldUpdate); | ||
React.useDebugValue(`Key path: ${JSON.stringify(keyPath)}`); | ||
React.useDebugValue(`State: ${JSON.stringify(next[0])}`); | ||
return next; | ||
}; | ||
@@ -386,0 +390,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
var U=Object.defineProperty,X=Object.defineProperties;var B=Object.getOwnPropertyDescriptors;var _=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var D=(a,l,i)=>l in a?U(a,l,{enumerable:!0,configurable:!0,writable:!0,value:i}):a[l]=i,x=(a,l)=>{for(var i in l||(l={}))Q.call(l,i)&&D(a,i,l[i]);if(_)for(var i of _(l))Z.call(l,i)&&D(a,i,l[i]);return a},N=(a,l)=>X(a,B(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 i(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var f=i(l);const h=e=>{const t=new Set;let r=e;return{subscribe(s){return t.add(s),()=>t.delete(s)},getSnapshot(){return r},update(s){const n=s(r);Object.is(n,r)||(r=n,t.forEach(o=>o()))}}},w=e=>Object.prototype.toString.call(e)==="[object Object]",V=e=>{if(w(e))return x({},e);if(Array.isArray(e))return[...e];throw new Error("shallowCopy expected a plain object or array")},T=Object.freeze({get(e){return e},set(e,t){return t}}),$=()=>T,j=(e,t,r)=>({get(s){const n=e.get(s);return t(n)},set(s,n){const o=e.get(s);return e.set(s,r(o,n))}}),I=(e,t)=>j(e,r=>r[t],(r,s)=>{const n=V(r);return n[t]=s,n}),F=(e,t)=>r=>{const s=e.get(r),n=t(s);return Object.is(s,n)?r:e.set(r,t(s))},H={isCalledInsideReactDevtools:()=>{var t;return(t=new Error().stack)==null?void 0:t.includes("react_devtools_backend")}},S=Symbol(),P=Symbol(),W=Symbol(),G=e=>Array.isArray(e)||w(e),K=(e,t)=>{const r=e.createUseLensState(e.lens);return function(n){const[o,c]=r(e.keyPath,n);return[O(o,t),c]}},O=(e,t)=>{if(!G(e))return e;if(Reflect.has(e,S))return Reflect.get(e,S);let r;const s=new Proxy(e,{get(n,o){if(o==="toJSON")return r!=null||(r=()=>n),r;if(o==="toLens")return t[P];if(o===S)return s;const c=n[o],u=t[o];return O(c,u)},ownKeys(n){return Reflect.ownKeys(n).concat(["toLens","toJSON"])},getOwnPropertyDescriptor(n,o){let c;if(o==="toLens"||o==="toJSON"?c={configurable:!0,enumerable:!0,writable:!1}:c=Object.getOwnPropertyDescriptor(n,o),c===void 0)return;const u=s[o];return{writable:c.writable,enumerable:c.enumerable,configurable:c.configurable,value:u}},preventExtensions(){return!0},isExtensible(){return!1},set(){throw new Error("Cannot set property on ProxyValue")},deleteProperty(){throw new Error("Cannot delete property on ProxyValue")}});return Object.defineProperty(e,S,{value:s,enumerable:!1,writable:!1,configurable:!1}),s},v=e=>{const t={};let r,s,n;const o=new Proxy({},{get(c,u){if(u!=="$$typeof"){if(u==="$key")return n!=null||(n=`Lens(${e.keyPath})`),n;if(u===P)return s!=null||(s=()=>o),s;if(u==="use")return r!=null||(r=K(e,o)),r;if(t[u]===void 0){const d=N(x({},e),{keyPath:[...e.keyPath,u],lens:I(e.lens,u)}),y=v(d);t[u]=y}return t[u]}},ownKeys(c){return["$key","use",W]},getOwnPropertyDescriptor(c,u){if(u==="$key"||u==="use")return{configurable:!0,enumerable:!0,writable:!1,value:o[u]};if(H.isCalledInsideReactDevtools())return{configurable:!0,enumerable:!1,value:void 0};throw new Error("ProxyLens threw because you tried to access all property descriptors\u2014probably through `{ ...lens }` or `Object.assign({}, lens)`. Doing this will break the type safety offered by this library so it is forbidden. Sorry, buddy pal.")},getPrototypeOf(){return null},preventExtensions(){return!0},isExtensible(){return!1},set(){throw new Error("Cannot set property on ProxyLens")},deleteProperty(){throw new Error("Cannot delete property on ProxyLens")}});return o},E=e=>v({createUseLensState:e,lens:$(),keyPath:[]}),g=e=>{if(typeof e=="boolean")return(t,r)=>e?t!==r:!1;if(typeof e=="function")return e;if(Array.isArray(e)){const t=Object.fromEntries(e.map(r=>[r,!0]));return g(t)}return(t,r)=>{let s=!1,n=!1,o,c;if(Array.isArray(t)?(s=!0,o=t):o=[t],Array.isArray(r)?(n=!0,c=r):c=[r],n!==s||o.length!==c.length)return!0;for(let u=0;u<o.length;u++){const d=o[u],y=c[u];for(const p in e)if(g(e[p])(d[p],y[p]))return!0}return!1}},b=Symbol(),Y=()=>!0,L=(e,t,r=Y)=>{const s=f.default.useRef(b),n=f.default.useRef(r),o=f.default.useRef(b);n.current!==r&&(o.current=b),n.current=r;const c=()=>{const y=s.current,p=t.get(e.getSnapshot());return Object.is(y,p)?y:y===b||(o.current===b&&(o.current=g(r)),o.current(y,p))?p:y},u=f.default.useSyncExternalStore(e.subscribe,c,c),d=f.default.useCallback(y=>e.update(F(t,y)),[e]);return s.current=u,[u,d]},m=Symbol(),A=e=>{const t=f.default.useRef(m);return t.current===m&&(t.current=e()),t.current},C=Symbol(),J=(e,t)=>{const r=A(()=>h(e));f.default.useEffect(()=>{r.update(()=>e)},[e]);const s=f.default.useRef(t);return s.current=t,f.default.useEffect(()=>r.subscribe(()=>s.current(r.getSnapshot())),[]),r},M=(e="Lens")=>{const t=f.default.createContext(C);t.displayName=`${e}(ExternalStoreContext)`;const r=E(n=>function(c,u){l.useDebugValue(c);const d=f.default.useContext(t);if(d===C)throw new Error("Cannot call `lens.use()` in a component outside of <LensProvider />");return L(d,n,u)}),s=n=>{const o=J(n.value,n.onChange);return f.default.createElement(t.Provider,{value:o},n.children)};return s.displayName=`${e}(Provider)`,[r,s]},R=e=>{const t=h(e);return[E(n=>function(c,u){return l.useDebugValue(c),L(t,n,u)}),{get current(){return t.getSnapshot()},set current(n){t.update(()=>n)}}]},q=e=>A(()=>R(e));a.stateful=R,a.stateless=M,a.useStateful=q,Object.defineProperty(a,"__esModule",{value:!0}),a[Symbol.toStringTag]="Module"}); | ||
var U=Object.defineProperty,X=Object.defineProperties;var B=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var _=(c,l,y)=>l in c?U(c,l,{enumerable:!0,configurable:!0,writable:!0,value:y}):c[l]=y,x=(c,l)=>{for(var y in l||(l={}))Q.call(l,y)&&_(c,y,l[y]);if(N)for(var y of N(l))Z.call(l,y)&&_(c,y,l[y]);return c},D=(c,l)=>X(c,B(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 y(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var i=y(l);const h=e=>{const t=new Set;let r=e;return{subscribe(s){return t.add(s),()=>t.delete(s)},getSnapshot(){return r},update(s){const n=s(r);Object.is(n,r)||(r=n,t.forEach(o=>o()))}}},w=e=>Object.prototype.toString.call(e)==="[object Object]",$=e=>{if(w(e))return x({},e);if(Array.isArray(e))return[...e];throw new Error("shallowCopy expected a plain object or array")},V=Object.freeze({get(e){return e},set(e,t){return t}}),T=()=>V,j=(e,t,r)=>({get(s){const n=e.get(s);return t(n)},set(s,n){const o=e.get(s);return e.set(s,r(o,n))}}),I=(e,t)=>j(e,r=>r[t],(r,s)=>{const n=$(r);return n[t]=s,n}),F=(e,t)=>r=>{const s=e.get(r),n=t(s);return Object.is(s,n)?r:e.set(r,t(s))},J={isCalledInsideReactDevtools:()=>{var t;return(t=new Error().stack)==null?void 0:t.includes("react_devtools_backend")}},S=Symbol(),O=Symbol(),H=Symbol(),K=e=>Array.isArray(e)||w(e),W=(e,t)=>{const r=e.createUseLensState(e.lens);return function(n){const[o,a]=r(e.keyPath,n);return[P(o,t),a]}},P=(e,t)=>{if(!K(e))return e;if(Reflect.has(e,S))return Reflect.get(e,S);let r;const s=new Proxy(e,{get(n,o){if(o==="toJSON")return r!=null||(r=()=>n),r;if(o==="toLens")return t[O];if(o===S)return s;const a=n[o],u=t[o];return P(a,u)},ownKeys(n){return Reflect.ownKeys(n).concat(["toLens","toJSON"])},getOwnPropertyDescriptor(n,o){let a;if(o==="toLens"||o==="toJSON"?a={configurable:!0,enumerable:!0,writable:!1}:a=Object.getOwnPropertyDescriptor(n,o),a===void 0)return;const u=s[o];return{writable:a.writable,enumerable:a.enumerable,configurable:a.configurable,value:u}},preventExtensions(){return!0},isExtensible(){return!1},set(){throw new Error("Cannot set property on ProxyValue")},deleteProperty(){throw new Error("Cannot delete property on ProxyValue")}});return Object.defineProperty(e,S,{value:s,enumerable:!1,writable:!1,configurable:!1}),s},v=e=>{const t={};let r,s,n;const o=new Proxy({},{get(a,u){if(u!=="$$typeof"){if(u==="$key")return n!=null||(n=`Lens(${e.keyPath})`),n;if(u===O)return s!=null||(s=()=>o),s;if(u==="use")return r!=null||(r=W(e,o)),r;if(t[u]===void 0){const d=D(x({},e),{keyPath:[...e.keyPath,u],lens:I(e.lens,u)}),f=v(d);t[u]=f}return t[u]}},ownKeys(a){return["$key","use",H]},getOwnPropertyDescriptor(a,u){if(u==="$key"||u==="use")return{configurable:!0,enumerable:!0,writable:!1,value:o[u]};if(J.isCalledInsideReactDevtools())return{configurable:!0,enumerable:!1,value:void 0};throw new Error("ProxyLens threw because you tried to access all property descriptors\u2014probably through `{ ...lens }` or `Object.assign({}, lens)`. Doing this will break the type safety offered by this library so it is forbidden. Sorry, buddy pal.")},getPrototypeOf(){return null},preventExtensions(){return!0},isExtensible(){return!1},set(){throw new Error("Cannot set property on ProxyLens")},deleteProperty(){throw new Error("Cannot delete property on ProxyLens")}});return o},E=e=>v({createUseLensState:e,lens:T(),keyPath:[]}),g=e=>{if(typeof e=="boolean")return(t,r)=>e?t!==r:!1;if(typeof e=="function")return e;if(Array.isArray(e)){const t=Object.fromEntries(e.map(r=>[r,!0]));return g(t)}return(t,r)=>{let s=!1,n=!1,o,a;if(Array.isArray(t)?(s=!0,o=t):o=[t],Array.isArray(r)?(n=!0,a=r):a=[r],n!==s||o.length!==a.length)return!0;for(let u=0;u<o.length;u++){const d=o[u],f=a[u];for(const p in e)if(g(e[p])(d[p],f[p]))return!0}return!1}},b=Symbol(),G=()=>!0,L=(e,t,r=G)=>{const s=i.default.useRef(b),n=i.default.useRef(r),o=i.default.useRef(b);n.current!==r&&(o.current=b),n.current=r;const a=()=>{const f=s.current,p=t.get(e.getSnapshot());return Object.is(f,p)?f:f===b||(o.current===b&&(o.current=g(r)),o.current(f,p))?p:f},u=i.default.useSyncExternalStore(e.subscribe,a,a),d=i.default.useCallback(f=>e.update(F(t,f)),[e]);return s.current=u,[u,d]},m=Symbol(),R=e=>{const t=i.default.useRef(m);return t.current===m&&(t.current=e()),t.current},A=Symbol(),Y=(e,t)=>{const r=R(()=>h(e));i.default.useEffect(()=>{r.update(()=>e)},[e]);const s=i.default.useRef(t);return s.current=t,i.default.useEffect(()=>r.subscribe(()=>s.current(r.getSnapshot())),[]),r},M=(e="Lens")=>{const t=i.default.createContext(A);t.displayName=`${e}(ExternalStoreContext)`;const r=E(n=>function(a,u){const d=i.default.useContext(t);if(d===A)throw new Error("Cannot call `lens.use()` in a component outside of <LensProvider />");const f=L(d,n,u);return i.default.useDebugValue(`Key path: ${JSON.stringify(a)}`),i.default.useDebugValue(`State: ${JSON.stringify(f[0])}`),f}),s=n=>{const o=Y(n.value,n.onChange);return i.default.createElement(t.Provider,{value:o},n.children)};return s.displayName=`${e}(Provider)`,[r,s]},C=e=>{const t=h(e);return[E(n=>function(a,u){const d=L(t,n,u);return i.default.useDebugValue(`Key path: ${JSON.stringify(a)}`),i.default.useDebugValue(`State: ${JSON.stringify(d[0])}`),d}),{get current(){return t.getSnapshot()},set current(n){t.update(()=>n)}}]},q=e=>R(()=>C(e));c.stateful=C,c.stateless=M,c.useStateful=q,Object.defineProperty(c,"__esModule",{value:!0}),c[Symbol.toStringTag]="Module"}); | ||
//# sourceMappingURL=concave.umd.js.map |
{ | ||
"name": "concave", | ||
"version": "0.0.10-alpha1", | ||
"version": "0.0.10-alpha2", | ||
"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
36939
536