@blac/react 0.0.52 → 0.0.54
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/index.cjs.js +1 -1
- package/index.cjs.js.map +1 -1
- package/index.es.js +56 -58
- package/index.es.js.map +1 -1
- package/package.json +4 -5
- package/useBloc.d.ts +0 -3
package/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("blac"),r=require("react"),g=(t,s)=>({subscribe:i=>{const c=t.addSubscriber({fn:()=>{try{i(t.state)}catch(o){console.error({e:o,bloc:t,dependencyArray:s})}},dependencyArray:s});return()=>{c()}},getSnapshot:()=>t.state,getServerSnapshot:()=>t.state}),R=t=>[t];class j{static useBloc(s,i){let{dependencySelector:c,id:o,props:h}=i??{};const b=r.useId(),u=r.useRef(new Set),a=r.useRef(new Set),p=new Set,f=r.useRef(!1);s.isolated&&(o=b);const l=B.Blac.getInstance().getBloc(s,{id:o,props:h,reconnect:!1});if(!l)throw new Error(`useBloc: could not resolve: ${s.name||s}`);const I=(e,n)=>{if(c)return c(e,n);if(typeof e!="object")return R(e);const S=[];for(const y of u.current)y in e&&S.push(e[y]);return S},{subscribe:m,getSnapshot:v,getServerSnapshot:x}=r.useMemo(()=>g(l,I),[l.createdAt]),d=r.useSyncExternalStore(m,v,x),E=r.useMemo(()=>{try{if(typeof d=="object")return new Proxy(d,{get(e,n){return u.current.add(n),a.current.add(n),f.current=!0,Reflect.get(e,n)}})}catch(e){B.Blac.instance.log("useBloc Error",e)}return d},[d,u,a]);return r.useLayoutEffect(()=>(u.current=new Set(a.current),()=>{setTimeout(()=>{f.current&&(a.current.clear(),f.current=!1)})}),[p]),[E,l]}}const w=j.useBloc;exports.externalBlocStore=g;exports.useBloc=w;
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|
package/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/externalBlocStore.ts","../src/useBloc.tsx"],"sourcesContent":["import { BlocGeneric, BlocHookDependencyArrayFn, BlocState } from 'blac';\n\nexport interface ExternalStore<\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n> {\n subscribe: (onStoreChange: () => void) => () => void;\n getSnapshot: () => S;\n getServerSnapshot?: () => S;\n}\n\nconst externalBlocStore = <\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n>(\n bloc: B,\n dependencyArray: BlocHookDependencyArrayFn<InstanceType<any>>,\n): ExternalStore<B, S> => {\n return {\n subscribe: (listener: (state: S) => void) => {\n const unSub = bloc.addSubscriber({\n fn: () => {\n try {\n listener(bloc.state);\n } catch (e) {\n console.error({\n e,\n bloc,\n dependencyArray,\n });\n }\n },\n dependencyArray,\n });\n\n return () => {\n unSub();\n };\n },\n getSnapshot: (): S => bloc.state,\n getServerSnapshot: (): S => bloc.state,\n };\n};\n\nexport default externalBlocStore;\n","import {\n Blac,\n BlocBase,\n BlocConstructor,\n BlocGeneric,\n BlocHookDependencyArrayFn,\n
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/externalBlocStore.ts","../src/useBloc.tsx"],"sourcesContent":["import { BlocGeneric, BlocHookDependencyArrayFn, BlocState } from 'blac';\n\nexport interface ExternalStore<\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n> {\n subscribe: (onStoreChange: () => void) => () => void;\n getSnapshot: () => S;\n getServerSnapshot?: () => S;\n}\n\nconst externalBlocStore = <\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n>(\n bloc: B,\n dependencyArray: BlocHookDependencyArrayFn<InstanceType<any>>,\n): ExternalStore<B, S> => {\n return {\n subscribe: (listener: (state: S) => void) => {\n const unSub = bloc.addSubscriber({\n fn: () => {\n try {\n listener(bloc.state);\n } catch (e) {\n console.error({\n e,\n bloc,\n dependencyArray,\n });\n }\n },\n dependencyArray,\n });\n\n return () => {\n unSub();\n };\n },\n getSnapshot: (): S => bloc.state,\n getServerSnapshot: (): S => bloc.state,\n };\n};\n\nexport default externalBlocStore;\n","import {\n Blac,\n BlocBase,\n BlocConstructor,\n BlocGeneric,\n BlocHookDependencyArrayFn,\n BlocState,\n InferPropsFromGeneric,\n} from 'blac';\nimport {\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport externalBlocStore from './externalBlocStore';\n\ntype HookTypes<B extends BlocConstructor<BlocGeneric>> = [\n BlocState<InstanceType<B>>,\n InstanceType<B>,\n];\n\nexport interface BlocHookOptions<B extends BlocGeneric<any, any>> {\n id?: string;\n dependencySelector?: BlocHookDependencyArrayFn<B>;\n props?: InferPropsFromGeneric<B>;\n}\n\nconst defaultDependencySelector: BlocHookDependencyArrayFn<any> = (s) => [s];\n\nexport class UseBlocClass {\n static useBloc<\n B extends BlocConstructor<BlocGeneric>,\n O extends BlocHookOptions<InstanceType<B>>,\n >(bloc: B, options?: O): HookTypes<B> {\n let { dependencySelector, id: blocId, props } = options ?? {};\n const rid = useId();\n const usedKeys = useRef<Set<string>>(new Set());\n const instanceKeys = useRef<Set<string>>(new Set());\n const renderInstance = new Set();\n const shouldClear = useRef(false);\n\n const base = bloc as unknown as BlocBase<B, O['props']>;\n const isIsolated = base.isolated;\n if (isIsolated) {\n blocId = rid;\n }\n\n const resolvedBloc = Blac.getInstance().getBloc(bloc, {\n id: blocId,\n props: props as any,\n reconnect: false,\n }) as InstanceType<B>;\n\n if (!resolvedBloc) {\n throw new Error(`useBloc: could not resolve: ${bloc.name || bloc}`);\n }\n\n // default options\n const dependencyArray: BlocHookDependencyArrayFn<InstanceType<B>> = (\n newState,\n oldState,\n ) => {\n if (dependencySelector) {\n return dependencySelector(newState, oldState);\n }\n if (typeof newState !== 'object') {\n return defaultDependencySelector(newState, oldState);\n }\n\n const used: string[] = [];\n for (const key of usedKeys.current) {\n if (key in newState) {\n used.push(newState[key as keyof typeof newState]);\n }\n }\n\n return used;\n };\n\n const { subscribe, getSnapshot, getServerSnapshot } = useMemo(\n () => externalBlocStore(resolvedBloc, dependencyArray),\n [resolvedBloc.createdAt],\n );\n\n const state = useSyncExternalStore<BlocState<InstanceType<B>>>(\n subscribe,\n getSnapshot,\n getServerSnapshot,\n );\n\n const returnState: BlocState<InstanceType<B>> = useMemo(() => {\n try {\n if (typeof state === 'object') {\n return new Proxy(state as any, {\n get(target, prop) {\n usedKeys.current.add(prop as string);\n instanceKeys.current.add(prop as string);\n shouldClear.current = true;\n return Reflect.get(target, prop);\n },\n });\n }\n } catch (error) {\n Blac.instance.log('useBloc Error', error);\n }\n return state;\n }, [state, usedKeys, instanceKeys]);\n\n useLayoutEffect(() => {\n usedKeys.current = new Set(instanceKeys.current);\n\n return () => {\n setTimeout(() => {\n if (shouldClear.current) {\n instanceKeys.current.clear();\n shouldClear.current = false;\n }\n });\n };\n }, [renderInstance]);\n\n return [returnState, resolvedBloc];\n }\n}\n\nconst useBloc = UseBlocClass.useBloc;\n\nexport default useBloc;\n"],"names":["externalBlocStore","bloc","dependencyArray","listener","unSub","e","defaultDependencySelector","s","UseBlocClass","options","dependencySelector","blocId","props","rid","useId","usedKeys","useRef","instanceKeys","renderInstance","shouldClear","resolvedBloc","Blac","newState","oldState","used","key","subscribe","getSnapshot","getServerSnapshot","useMemo","state","useSyncExternalStore","returnState","target","prop","error","useLayoutEffect","useBloc"],"mappings":"2HAWMA,EAAoB,CAIxBC,EACAC,KAEO,CACL,UAAYC,GAAiC,CACrC,MAAAC,EAAQH,EAAK,cAAc,CAC/B,GAAI,IAAM,CACJ,GAAA,CACFE,EAASF,EAAK,KAAK,QACZI,EAAG,CACV,QAAQ,MAAM,CACZ,EAAAA,EACA,KAAAJ,EACA,gBAAAC,CAAA,CACD,CACH,CACF,EACA,gBAAAA,CAAA,CACD,EAED,MAAO,IAAM,CACLE,GAAA,CAEV,EACA,YAAa,IAASH,EAAK,MAC3B,kBAAmB,I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Q,IAAIc,EAAQC,CAAI,CACjC,CAAA,CACD,QAEIC,EAAO,CACTd,EAAAA,KAAA,SAAS,IAAI,gBAAiBc,CAAK,CAC1C,CACO,OAAAL,CACN,EAAA,CAACA,EAAOf,EAAUE,CAAY,CAAC,EAElCmB,OAAAA,EAAAA,gBAAgB,KACdrB,EAAS,QAAU,IAAI,IAAIE,EAAa,OAAO,EAExC,IAAM,CACX,WAAW,IAAM,CACXE,EAAY,UACdF,EAAa,QAAQ,QACrBE,EAAY,QAAU,GACxB,CACD,CAAA,GAEF,CAACD,CAAc,CAAC,EAEZ,CAACc,EAAaZ,CAAY,CACnC,CACF,CAEA,MAAMiB,EAAU7B,EAAa"}
|
package/index.es.js
CHANGED
|
@@ -1,81 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const k = (s, e) => ({
|
|
7
|
-
subscribe: (t) => {
|
|
8
|
-
const n = s.addSubscriber({
|
|
1
|
+
import { Blac as p } from "blac";
|
|
2
|
+
import { useId as w, useRef as f, useMemo as B, useSyncExternalStore as j, useLayoutEffect as C } from "react";
|
|
3
|
+
const K = (t, r) => ({
|
|
4
|
+
subscribe: (d) => {
|
|
5
|
+
const n = t.addSubscriber({
|
|
9
6
|
fn: () => {
|
|
10
7
|
try {
|
|
11
|
-
t
|
|
12
|
-
} catch (
|
|
8
|
+
d(t.state);
|
|
9
|
+
} catch (o) {
|
|
13
10
|
console.error({
|
|
14
|
-
e:
|
|
15
|
-
bloc:
|
|
16
|
-
dependencyArray:
|
|
11
|
+
e: o,
|
|
12
|
+
bloc: t,
|
|
13
|
+
dependencyArray: r
|
|
17
14
|
});
|
|
18
15
|
}
|
|
19
16
|
},
|
|
20
|
-
dependencyArray:
|
|
17
|
+
dependencyArray: r
|
|
21
18
|
});
|
|
22
19
|
return () => {
|
|
23
20
|
n();
|
|
24
21
|
};
|
|
25
22
|
},
|
|
26
|
-
getSnapshot: () =>
|
|
27
|
-
getServerSnapshot: () =>
|
|
28
|
-
}),
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
let
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
K in r && d.push(r[K]);
|
|
37
|
-
return d;
|
|
38
|
-
} : (r) => [r], y, g;
|
|
39
|
-
typeof t == "object" && (f = t.dependencySelector ?? f, y = t.id, g = t.props ?? g), e.isolated && (y = n);
|
|
40
|
-
const u = h.getInstance().getBloc(e, {
|
|
41
|
-
id: y,
|
|
23
|
+
getSnapshot: () => t.state,
|
|
24
|
+
getServerSnapshot: () => t.state
|
|
25
|
+
}), R = (t) => [t];
|
|
26
|
+
class k {
|
|
27
|
+
static useBloc(r, d) {
|
|
28
|
+
let { dependencySelector: n, id: o, props: g } = d ?? {};
|
|
29
|
+
const h = w(), c = f(/* @__PURE__ */ new Set()), u = f(/* @__PURE__ */ new Set()), m = /* @__PURE__ */ new Set(), i = f(!1);
|
|
30
|
+
r.isolated && (o = h);
|
|
31
|
+
const a = p.getInstance().getBloc(r, {
|
|
32
|
+
id: o,
|
|
42
33
|
props: g,
|
|
43
34
|
reconnect: !1
|
|
44
35
|
});
|
|
45
|
-
if (!
|
|
46
|
-
throw new Error(`useBloc: could not resolve: ${
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
if (!a)
|
|
37
|
+
throw new Error(`useBloc: could not resolve: ${r.name || r}`);
|
|
38
|
+
const I = (e, s) => {
|
|
39
|
+
if (n)
|
|
40
|
+
return n(e, s);
|
|
41
|
+
if (typeof e != "object")
|
|
42
|
+
return R(e);
|
|
43
|
+
const S = [];
|
|
44
|
+
for (const y of c.current)
|
|
45
|
+
y in e && S.push(e[y]);
|
|
46
|
+
return S;
|
|
47
|
+
}, { subscribe: b, getSnapshot: v, getServerSnapshot: x } = B(
|
|
48
|
+
() => K(a, I),
|
|
49
|
+
[a.createdAt]
|
|
50
|
+
), l = j(
|
|
51
51
|
b,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
),
|
|
52
|
+
v,
|
|
53
|
+
x
|
|
54
|
+
), E = B(() => {
|
|
55
55
|
try {
|
|
56
|
-
if (
|
|
57
|
-
return new Proxy(
|
|
58
|
-
get(
|
|
59
|
-
return
|
|
56
|
+
if (typeof l == "object")
|
|
57
|
+
return new Proxy(l, {
|
|
58
|
+
get(e, s) {
|
|
59
|
+
return c.current.add(s), u.current.add(s), i.current = !0, Reflect.get(e, s);
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
|
-
} catch (
|
|
63
|
-
|
|
62
|
+
} catch (e) {
|
|
63
|
+
p.instance.log("useBloc Error", e);
|
|
64
64
|
}
|
|
65
|
-
return
|
|
66
|
-
}, [
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}, [
|
|
65
|
+
return l;
|
|
66
|
+
}, [l, c, u]);
|
|
67
|
+
return C(() => (c.current = new Set(u.current), () => {
|
|
68
|
+
setTimeout(() => {
|
|
69
|
+
i.current && (u.current.clear(), i.current = !1);
|
|
70
|
+
});
|
|
71
|
+
}), [m]), [E, a];
|
|
72
72
|
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
let S = c;
|
|
76
|
-
const $ = S.useBloc;
|
|
73
|
+
}
|
|
74
|
+
const P = k.useBloc;
|
|
77
75
|
export {
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
K as externalBlocStore,
|
|
77
|
+
P as useBloc
|
|
80
78
|
};
|
|
81
79
|
//# sourceMappingURL=index.es.js.map
|
package/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/externalBlocStore.ts","../src/useBloc.tsx"],"sourcesContent":["import { BlocGeneric, BlocHookDependencyArrayFn, BlocState } from 'blac';\n\nexport interface ExternalStore<\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n> {\n subscribe: (onStoreChange: () => void) => () => void;\n getSnapshot: () => S;\n getServerSnapshot?: () => S;\n}\n\nconst externalBlocStore = <\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n>(\n bloc: B,\n dependencyArray: BlocHookDependencyArrayFn<InstanceType<any>>,\n): ExternalStore<B, S> => {\n return {\n subscribe: (listener: (state: S) => void) => {\n const unSub = bloc.addSubscriber({\n fn: () => {\n try {\n listener(bloc.state);\n } catch (e) {\n console.error({\n e,\n bloc,\n dependencyArray,\n });\n }\n },\n dependencyArray,\n });\n\n return () => {\n unSub();\n };\n },\n getSnapshot: (): S => bloc.state,\n getServerSnapshot: (): S => bloc.state,\n };\n};\n\nexport default externalBlocStore;\n","import {\n Blac,\n BlocBase,\n BlocConstructor,\n BlocGeneric,\n BlocHookDependencyArrayFn,\n
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/externalBlocStore.ts","../src/useBloc.tsx"],"sourcesContent":["import { BlocGeneric, BlocHookDependencyArrayFn, BlocState } from 'blac';\n\nexport interface ExternalStore<\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n> {\n subscribe: (onStoreChange: () => void) => () => void;\n getSnapshot: () => S;\n getServerSnapshot?: () => S;\n}\n\nconst externalBlocStore = <\n B extends BlocGeneric<any, any>,\n S extends BlocState<B>,\n>(\n bloc: B,\n dependencyArray: BlocHookDependencyArrayFn<InstanceType<any>>,\n): ExternalStore<B, S> => {\n return {\n subscribe: (listener: (state: S) => void) => {\n const unSub = bloc.addSubscriber({\n fn: () => {\n try {\n listener(bloc.state);\n } catch (e) {\n console.error({\n e,\n bloc,\n dependencyArray,\n });\n }\n },\n dependencyArray,\n });\n\n return () => {\n unSub();\n };\n },\n getSnapshot: (): S => bloc.state,\n getServerSnapshot: (): S => bloc.state,\n };\n};\n\nexport default externalBlocStore;\n","import {\n Blac,\n BlocBase,\n BlocConstructor,\n BlocGeneric,\n BlocHookDependencyArrayFn,\n BlocState,\n InferPropsFromGeneric,\n} from 'blac';\nimport {\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport externalBlocStore from './externalBlocStore';\n\ntype HookTypes<B extends BlocConstructor<BlocGeneric>> = [\n BlocState<InstanceType<B>>,\n InstanceType<B>,\n];\n\nexport interface BlocHookOptions<B extends BlocGeneric<any, any>> {\n id?: string;\n dependencySelector?: BlocHookDependencyArrayFn<B>;\n props?: InferPropsFromGeneric<B>;\n}\n\nconst defaultDependencySelector: BlocHookDependencyArrayFn<any> = (s) => [s];\n\nexport class UseBlocClass {\n static useBloc<\n B extends BlocConstructor<BlocGeneric>,\n O extends BlocHookOptions<InstanceType<B>>,\n >(bloc: B, options?: O): HookTypes<B> {\n let { dependencySelector, id: blocId, props } = options ?? {};\n const rid = useId();\n const usedKeys = useRef<Set<string>>(new Set());\n const instanceKeys = useRef<Set<string>>(new Set());\n const renderInstance = new Set();\n const shouldClear = useRef(false);\n\n const base = bloc as unknown as BlocBase<B, O['props']>;\n const isIsolated = base.isolated;\n if (isIsolated) {\n blocId = rid;\n }\n\n const resolvedBloc = Blac.getInstance().getBloc(bloc, {\n id: blocId,\n props: props as any,\n reconnect: false,\n }) as InstanceType<B>;\n\n if (!resolvedBloc) {\n throw new Error(`useBloc: could not resolve: ${bloc.name || bloc}`);\n }\n\n // default options\n const dependencyArray: BlocHookDependencyArrayFn<InstanceType<B>> = (\n newState,\n oldState,\n ) => {\n if (dependencySelector) {\n return dependencySelector(newState, oldState);\n }\n if (typeof newState !== 'object') {\n return defaultDependencySelector(newState, oldState);\n }\n\n const used: string[] = [];\n for (const key of usedKeys.current) {\n if (key in newState) {\n used.push(newState[key as keyof typeof newState]);\n }\n }\n\n return used;\n };\n\n const { subscribe, getSnapshot, getServerSnapshot } = useMemo(\n () => externalBlocStore(resolvedBloc, dependencyArray),\n [resolvedBloc.createdAt],\n );\n\n const state = useSyncExternalStore<BlocState<InstanceType<B>>>(\n subscribe,\n getSnapshot,\n getServerSnapshot,\n );\n\n const returnState: BlocState<InstanceType<B>> = useMemo(() => {\n try {\n if (typeof state === 'object') {\n return new Proxy(state as any, {\n get(target, prop) {\n usedKeys.current.add(prop as string);\n instanceKeys.current.add(prop as string);\n shouldClear.current = true;\n return Reflect.get(target, prop);\n },\n });\n }\n } catch (error) {\n Blac.instance.log('useBloc Error', error);\n }\n return state;\n }, [state, usedKeys, instanceKeys]);\n\n useLayoutEffect(() => {\n usedKeys.current = new Set(instanceKeys.current);\n\n return () => {\n setTimeout(() => {\n if (shouldClear.current) {\n instanceKeys.current.clear();\n shouldClear.current = false;\n }\n });\n };\n }, [renderInstance]);\n\n return [returnState, resolvedBloc];\n }\n}\n\nconst useBloc = UseBlocClass.useBloc;\n\nexport default useBloc;\n"],"names":["externalBlocStore","bloc","dependencyArray","listener","unSub","e","defaultDependencySelector","s","UseBlocClass","options","dependencySelector","blocId","props","rid","useId","usedKeys","useRef","instanceKeys","renderInstance","shouldClear","resolvedBloc","Blac","newState","oldState","used","key","subscribe","getSnapshot","getServerSnapshot","useMemo","state","useSyncExternalStore","returnState","target","prop","error","useLayoutEffect","useBloc"],"mappings":";;AAWM,MAAAA,IAAoB,CAIxBC,GACAC,OAEO;AAAA,EACL,WAAW,CAACC,MAAiC;AACrC,UAAAC,IAAQH,EAAK,cAAc;AAAA,MAC/B,IAAI,MAAM;AACJ,YAAA;AACF,UAAAE,EAASF,EAAK,KAAK;AAAA,iBACZI,GAAG;AACV,kBAAQ,MAAM;AAAA,YACZ,GAAAA;AAAA,YACA,MAAAJ;AAAA,YACA,iBAAAC;AAAA,UAAA,CACD;AAAA,QACH;AAAA,MACF;AAAA,MACA,iBAAAA;AAAA,IAAA,CACD;AAED,WAAO,MAAM;AACL,MAAAE;IAAA;AAAA,EAEV;AAAA,EACA,aAAa,MAASH,EAAK;AAAA,EAC3B,mBAAmB,MAASA,EAAK;AAAA,ICX/BK,IAA4D,CAACC,MAAM,CAACA,CAAC;AAEpE,MAAMC,EAAa;AAAA,EACxB,OAAO,QAGLP,GAASQ,GAA2B;AACpC,QAA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AAA,eAEIC,GAAO;AACT,QAAAd,EAAA,SAAS,IAAI,iBAAiBc,CAAK;AAAA,MAC1C;AACO,aAAAL;AAAA,IACN,GAAA,CAACA,GAAOf,GAAUE,CAAY,CAAC;AAElC,WAAAmB,EAAgB,OACdrB,EAAS,UAAU,IAAI,IAAIE,EAAa,OAAO,GAExC,MAAM;AACX,iBAAW,MAAM;AACf,QAAIE,EAAY,YACdF,EAAa,QAAQ,SACrBE,EAAY,UAAU;AAAA,MACxB,CACD;AAAA,IAAA,IAEF,CAACD,CAAc,CAAC,GAEZ,CAACc,GAAaZ,CAAY;AAAA,EACnC;AACF;AAEA,MAAMiB,IAAU7B,EAAa;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blac/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.54",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "index.cjs.js",
|
|
6
6
|
"module": "index.es.js",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "vite build",
|
|
21
21
|
"pub:patch": "npm run build && bun publish.ts && cd dist && npm publish",
|
|
22
|
+
"pub:patch:next": "npm run build && bun publish.ts && cd dist && npm publish --tag next",
|
|
22
23
|
"dev": "bun dev.ts",
|
|
23
24
|
"prettier": "prettier --write ./src",
|
|
24
25
|
"test": "vitest --config vitest.config.ts",
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
"pub": "npm run build && npm publish"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
30
|
+
"react": "^18",
|
|
29
31
|
"blac": "*"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
@@ -33,13 +35,10 @@
|
|
|
33
35
|
"@testing-library/jest-dom": "^6.4.6",
|
|
34
36
|
"@testing-library/react": "^16.0.0",
|
|
35
37
|
"@testing-library/user-event": "^14.5.2",
|
|
36
|
-
"@types/react": "^18.3.3",
|
|
37
|
-
"@types/react-dom": "^18.3.0",
|
|
38
|
-
"@vitest/browser": "^1.6.0",
|
|
39
|
-
"react": "^18.3.1",
|
|
40
38
|
"@typescript-eslint/eslint-plugin": "^7.13.1",
|
|
41
39
|
"@typescript-eslint/parser": "^7.13.1",
|
|
42
40
|
"@vitejs/plugin-react-refresh": "^1.3.6",
|
|
41
|
+
"@vitest/browser": "^1.6.0",
|
|
43
42
|
"@vitest/coverage-v8": "^1.6.0",
|
|
44
43
|
"eslint": "^9.5.0",
|
|
45
44
|
"jsdom": "^24.1.0",
|
package/useBloc.d.ts
CHANGED
|
@@ -8,11 +8,8 @@ export interface BlocHookOptions<B extends BlocGeneric<any, any>> {
|
|
|
8
8
|
id?: string;
|
|
9
9
|
dependencySelector?: BlocHookDependencyArrayFn<B>;
|
|
10
10
|
props?: InferPropsFromGeneric<B>;
|
|
11
|
-
inferStateUsage?: boolean;
|
|
12
11
|
}
|
|
13
12
|
export declare class UseBlocClass {
|
|
14
|
-
static ridUsedKeys: Map<string, Set<string>>;
|
|
15
|
-
static getUsedKeys: (rid: string) => Set<string>;
|
|
16
13
|
static useBloc<B extends BlocConstructor<BlocGeneric>, O extends BlocHookOptions<InstanceType<B>>>(bloc: B, options?: O): HookTypes<B>;
|
|
17
14
|
}
|
|
18
15
|
declare const useBloc: typeof UseBlocClass.useBloc;
|