@lensmcp/valtio-instrumentation 1.21.2 → 1.21.4

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.
Files changed (2) hide show
  1. package/lib/snapshot.js +1 -1
  2. package/package.json +2 -2
package/lib/snapshot.js CHANGED
@@ -1 +1 @@
1
- "use strict";var $=Object.defineProperty;var a=(t,o)=>$(t,"name",{value:o,configurable:!0});var k=Object.defineProperty,i=a((t,o)=>k(t,"name",{value:o,configurable:!0}),"c");import{useCallback as P,useEffect as f,useLayoutEffect as w,useMemo as l,useRef as b,useSyncExternalStore as M}from"react";import{snapshot as I,subscribe as T}from"valtio/vanilla";import{useSnapshot as x}from"valtio/react";import{affectedToPathList as E,createProxy as L,isChanged as C}from"proxy-compare";import{useLensmcpContext as S,publish as W}from"@lensmcp/react-instrumentation";import{addSubscription as N,removeSubscription as _,storeIdOf as A}from"./store-registry.js";const H=new WeakMap;export function useTrackedSnapshot(t,o){const r=S(),e=o.path??"",n=r.componentInstanceId??"react:component:anonymous";return f(()=>(c("added",o.storeId,e,n),()=>{c("removed",o.storeId,e,n)}),[o.storeId,e,n]),x(t)}a(useTrackedSnapshot,"useTrackedSnapshot"),i(useTrackedSnapshot,"useTrackedSnapshot");export function useSnapshot(t){const o=A(t)??"valtio:store:anonymous",r=S().componentInstanceId??"react:component:anonymous",e=l(()=>t&&new WeakMap,[t]),n=b(void 0);let h=!0;const p=M(P(s=>{const u=T(t,s,!1);return s(),u},[t]),()=>{const s=I(t);try{if(!h&&n.current&&e&&!C(n.current,s,e,new WeakMap))return n.current}catch{}return s},()=>I(t));h=!1,w(()=>{n.current=p});const y=l(()=>new WeakMap,[]),d=b(void 0);return d.current||(d.current=new Set),f(()=>{const s=e?E(p,e,!0).map(g=>truncatePath(g)):[],u=new Set(s.length?s:[""]);v(d.current,u,o,r)}),f(()=>{const s=d.current;return()=>{for(const u of[...s])c("removed",o,u,r);s.clear()}},[o,r]),e?L(p,e,y,H):p}a(useSnapshot,"useSnapshot"),i(useSnapshot,"useSnapshot");const m=(()=>{const t=typeof process<"u"?process.env?.LENSMCP_VALTIO_PATH_DEPTH:void 0,o=Number(t);return Number.isFinite(o)&&o>=0&&o<=20?Math.floor(o):3})();export function truncatePath(t){const o=m>0&&m<t.length?m:t.length;let r="";for(let e=0;e<o;e++)r+=e===0?String(t[e]):`.${String(t[e])}`;return r}a(truncatePath,"truncatePath"),i(truncatePath,"truncatePath");function v(t,o,r,e){for(const n of o)t.has(n)||c("added",r,n,e);for(const n of[...t])o.has(n)||c("removed",r,n,e);t.clear();for(const n of o)t.add(n)}a(v,"N"),i(v,"reconcileSubscriptions");function c(t,o,r,e){t==="added"?N({storeId:o,path:r,componentInstanceId:e}):_({storeId:o,path:r,componentInstanceId:e});const n=t==="added"?"sub":"unsub";W({source:"valtio",category:"state",severity:"debug",title:`subscription-${t} ${o}.${r}`,fingerprint:`valtio-${n}:${o}:${r}:${e}`,raw:{kind:`subscription-${t}`,subscription:{storeId:o,path:r,componentInstanceId:e}}})}a(c,"i"),i(c,"emitSubscription");
1
+ "use strict";var $=Object.defineProperty;var c=(t,o)=>$(t,"name",{value:o,configurable:!0});var M=Object.defineProperty,p=c((t,o)=>M(t,"name",{value:o,configurable:!0}),"i");import{useCallback as w,useEffect as I,useLayoutEffect as x,useMemo as b,useRef as S,useSyncExternalStore as T}from"react";import{snapshot as g,subscribe as C}from"valtio/vanilla";import{useSnapshot as E}from"valtio/react";import{affectedToPathList as W,createProxy as N,isChanged as _}from"proxy-compare";import{useComponentIdentity as v,useLensmcpContext as y,publish as A}from"@lensmcp/react-instrumentation";import{addSubscription as H,removeSubscription as O,storeIdOf as R}from"./store-registry.js";const j=new WeakMap;export function useTrackedSnapshot(t,o){const r=y(),n=o.path??"",s=v(),e=r.componentInstanceId??s.componentInstanceId;return I(()=>(u("added",o.storeId,n,e,s.componentLogicalId),()=>{u("removed",o.storeId,n,e,s.componentLogicalId)}),[o.storeId,n,e]),E(t)}c(useTrackedSnapshot,"useTrackedSnapshot"),p(useTrackedSnapshot,"useTrackedSnapshot");export function useSnapshot(t){const o=R(t)??"valtio:store:anonymous",r=y(),n=v(),s=r.componentInstanceId??n.componentInstanceId,e=b(()=>t&&new WeakMap,[t]),d=S(void 0);let h=!0;const m=T(w(a=>{const i=C(t,a,!1);return a(),i},[t]),()=>{const a=g(t);try{if(!h&&d.current&&e&&!_(d.current,a,e,new WeakMap))return d.current}catch{}return a},()=>g(t));h=!1,x(()=>{d.current=m});const k=b(()=>new WeakMap,[]),f=S(void 0);return f.current||(f.current=new Set),I(()=>{const a=e?W(m,e,!0).map(P=>truncatePath(P)):[],i=new Set(a.length?a:[""]);L(f.current,i,o,s,n.componentLogicalId)}),I(()=>{const a=f.current;return()=>{for(const i of[...a])u("removed",o,i,s,n.componentLogicalId);a.clear()}},[o,s]),e?N(m,e,k,j):m}c(useSnapshot,"useSnapshot"),p(useSnapshot,"useSnapshot");const l=(()=>{const t=typeof process<"u"?process.env?.LENSMCP_VALTIO_PATH_DEPTH:void 0,o=Number(t);return Number.isFinite(o)&&o>=0&&o<=20?Math.floor(o):3})();export function truncatePath(t){const o=l>0&&l<t.length?l:t.length;let r="";for(let n=0;n<o;n++)r+=n===0?String(t[n]):`.${String(t[n])}`;return r}c(truncatePath,"truncatePath"),p(truncatePath,"truncatePath");function L(t,o,r,n,s){for(const e of o)t.has(e)||u("added",r,e,n,s);for(const e of[...t])o.has(e)||u("removed",r,e,n,s);t.clear();for(const e of o)t.add(e)}c(L,"R"),p(L,"reconcileSubscriptions");function u(t,o,r,n,s){t==="added"?H({storeId:o,path:r,componentInstanceId:n}):O({storeId:o,path:r,componentInstanceId:n});const e=t==="added"?"sub":"unsub";A({source:"valtio",category:"state",severity:"debug",title:`subscription-${t} ${o}.${r}`,fingerprint:`valtio-${e}:${o}:${r}`,raw:{kind:`subscription-${t}`,subscription:{storeId:o,path:r,componentInstanceId:n,...s?{componentLogicalId:s}:{}}}})}c(u,"a"),p(u,"emitSubscription");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensmcp/valtio-instrumentation",
3
- "version": "1.21.2",
3
+ "version": "1.21.4",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
@@ -14,7 +14,7 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@lensmcp/react-instrumentation": "1.21.2",
17
+ "@lensmcp/react-instrumentation": "1.21.4",
18
18
  "proxy-compare": "^3.0.0",
19
19
  "tslib": "^2.3.0"
20
20
  },