@lensmcp/valtio-instrumentation 1.18.6 → 1.18.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/lib/snapshot.d.ts +3 -1
- package/lib/snapshot.js +1 -1
- package/package.json +2 -2
package/lib/snapshot.d.ts
CHANGED
|
@@ -14,5 +14,7 @@ export declare function useTrackedSnapshot<T extends object>(target: T, opts: Us
|
|
|
14
14
|
* `proxy()`; falls back to a single root subscription when nothing is read.
|
|
15
15
|
*/
|
|
16
16
|
export declare function useSnapshot<T extends object>(target: T): T;
|
|
17
|
-
/** Join a visited-property path, truncated to {@link SUB_PATH_DEPTH} segments (0 ⇒ no truncation).
|
|
17
|
+
/** Join a visited-property path, truncated to {@link SUB_PATH_DEPTH} segments (0 ⇒ no truncation).
|
|
18
|
+
* Built in ONE pass with no intermediate arrays — this runs per visited property per snapshot,
|
|
19
|
+
* hot enough to chart in commit-storm profiles when written as map().slice().join(). */
|
|
18
20
|
export declare function truncatePath(parts: readonly (string | symbol)[]): string;
|
package/lib/snapshot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/valtio-instrumentation",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.8",
|
|
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.18.
|
|
17
|
+
"@lensmcp/react-instrumentation": "1.18.8",
|
|
18
18
|
"proxy-compare": "^3.0.0",
|
|
19
19
|
"tslib": "^2.3.0"
|
|
20
20
|
},
|