@blac/react 2.0.0-rc-11 → 2.0.0-rc-13

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/dist/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("@blac/core"),r=require("react");function x(n,e){const b=r.useRef(0);b.current++;const l=r.useRef({}),c=r.useMemo(()=>new S.BlacAdapter({componentRef:l,blocConstructor:n},{id:e==null?void 0:e.id,dependencies:e==null?void 0:e.dependencies,props:e==null?void 0:e.props,onMount:e==null?void 0:e.onMount,onUnmount:e==null?void 0:e.onUnmount}),[]);c.resetConsumerTracking();const t=r.useRef(0);r.useEffect(()=>{t.current++,c.options={id:e==null?void 0:e.id,dependencies:e==null?void 0:e.dependencies,props:e==null?void 0:e.props,onMount:e==null?void 0:e.onMount,onUnmount:e==null?void 0:e.onUnmount},(e==null?void 0:e.props)!==void 0&&c.updateProps(e.props)},[e==null?void 0:e.props,e==null?void 0:e.id,e==null?void 0:e.dependencies,e==null?void 0:e.onMount,e==null?void 0:e.onUnmount]);const R=r.useRef(0);r.useEffect(()=>(R.current++,c.mount(),()=>{c.unmount()}),[c.blocInstance]);const M=r.useRef(0),u=r.useMemo(()=>(M.current++,s=>{const B=c.createSubscription({onChange:()=>{s()}});return()=>{B()}}),[c.blocInstance]),a=r.useRef(0),d=r.useRef(0),f=r.useSyncExternalStore(u,()=>(a.current++,c.blocInstance.state),()=>{const s=c.blocInstance;return d.current++,s.state}),m=r.useRef(0),g=r.useMemo(()=>(m.current++,c.getProxyState(f)),[f]),y=r.useRef(0),I=r.useMemo(()=>(y.current++,c.getProxyBlocInstance()),[c.blocInstance]);return r.useEffect(()=>{c.updateLastNotified(l.current)}),[g,I]}function U(n,e={}){const b=r.useRef(`external-${S.generateUUID()}`),l=r.useRef(new Set),c=r.useRef(new Set),t=r.useRef(null),R=r.useMemo(()=>{const u=S.Blac.getInstance();if(n.constructor.isolated||n.isolated){const d=new n(e==null?void 0:e.props),f=(e==null?void 0:e.id)||`${n.name}_${S.generateUUID()}`;return d._updateId(f),u.activateBloc(d),d}return u.getBloc(n,{id:e==null?void 0:e.id,props:e==null?void 0:e.props})},[n,e==null?void 0:e.id]),M=r.useMemo(()=>({getSnapshot:()=>{const u=t.current;return u?u.state:void 0},subscribe:u=>{const a=t.current;if(!a)return()=>{};const d=(m,g)=>{try{l.current.clear(),c.current.clear(),e.selector&&a&&e.selector(m,g,a),u.length>0?u(m):u()}catch(y){console.error("Listener error in useExternalBlocStore:",y)}};return a._observer.subscribe({id:b.current,fn:d})},getServerSnapshot:()=>{const u=t.current;return u?u.state:void 0}}),[]);return t.current=R,{externalStore:M,instance:t,usedKeys:l,usedClassPropKeys:c,rid:b.current}}exports.useBloc=x;exports.useExternalBlocStore=U;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("@blac/core"),r=require("react");function I(n,e){const b=r.useRef(0);b.current++;const l=r.useRef({}),c=r.useMemo(()=>new S.BlacAdapter({componentRef:l,blocConstructor:n},{id:e==null?void 0:e.id,dependencies:e==null?void 0:e.dependencies,props:e==null?void 0:e.props,onMount:e==null?void 0:e.onMount,onUnmount:e==null?void 0:e.onUnmount}),[]);c.resetConsumerTracking();const t=r.useRef(0);r.useEffect(()=>{t.current++,c.options={id:e==null?void 0:e.id,dependencies:e==null?void 0:e.dependencies,props:e==null?void 0:e.props,onMount:e==null?void 0:e.onMount,onUnmount:e==null?void 0:e.onUnmount},(e==null?void 0:e.props)!==void 0&&c.updateProps(e.props)},[e==null?void 0:e.props,e==null?void 0:e.id,e==null?void 0:e.dependencies,e==null?void 0:e.onMount,e==null?void 0:e.onUnmount]);const R=r.useRef(0);r.useEffect(()=>(R.current++,c.mount(),()=>{c.unmount()}),[c.blocInstance]);const B=r.useRef(0),u=r.useMemo(()=>(B.current++,d=>{const y=c.createSubscription({onChange:()=>{d()}});return()=>{y()}}),[c.blocInstance]),a=r.useRef(0),s=r.useRef(0),f=r.useSyncExternalStore(u,()=>(a.current++,c.blocInstance.state),()=>{const d=c.blocInstance;return s.current++,d.state}),m=r.useRef(0),M=r.useMemo(()=>(m.current++,c.getProxyState(f)),[f]),g=r.useRef(0),x=r.useMemo(()=>(g.current++,c.getProxyBlocInstance()),[c.blocInstance]);return r.useEffect(()=>{c.updateLastNotified(l.current)}),[M,x]}function U(n,e={}){const b=r.useRef(`external-${S.generateUUID()}`),l=r.useRef(new Set),c=r.useRef(new Set),t=r.useRef(null),R=r.useMemo(()=>{const u=S.Blac.getInstance();if(n.constructor.isolated||n.isolated){const s=new n(e==null?void 0:e.props),f=(e==null?void 0:e.id)||`${n.name}_${S.generateUUID()}`;return s._updateId(f),u.activateBloc(s),s}return u.getBloc(n,{id:e==null?void 0:e.id,props:e==null?void 0:e.props})},[n,e==null?void 0:e.id]),B=r.useMemo(()=>({getSnapshot:()=>{const u=t.current;return u?u.state:void 0},subscribe:u=>{const a=t.current;if(!a)return()=>{};const s=(m,M)=>{try{l.current.clear(),c.current.clear(),e.selector&&a&&e.selector(m,M,a),u.length>0?u(m):u()}catch(g){console.error("Listener error in useExternalBlocStore:",g)}};return a._observer.subscribe({id:b.current,fn:s})},getServerSnapshot:()=>{const u=t.current;return u?u.state:void 0}}),[]);return t.current=R,{externalStore:B,instance:t,usedKeys:l,usedClassPropKeys:c,rid:b.current}}exports.useBloc=I;exports.useBlocNext=I;exports.useExternalBlocStore=U;
2
2
  //# sourceMappingURL=index.cjs.js.map
package/dist/index.d.ts CHANGED
@@ -40,13 +40,15 @@ InstanceType<B>
40
40
  /**
41
41
  * React hook for integrating with Blac state management
42
42
  */
43
- export declare function useBloc<B extends BlocConstructor<BlocBase<any>>>(blocConstructor: B, options?: {
43
+ declare function useBloc<B extends BlocConstructor<BlocBase<any>>>(blocConstructor: B, options?: {
44
44
  props?: ConstructorParameters<B>[0];
45
45
  id?: string;
46
46
  dependencies?: (bloc: InstanceType<B>) => unknown[];
47
47
  onMount?: (bloc: InstanceType<B>) => void;
48
48
  onUnmount?: (bloc: InstanceType<B>) => void;
49
49
  }): HookTypes<B>;
50
+ export { useBloc }
51
+ export { useBloc as useBlocNext }
50
52
 
51
53
  /**
52
54
  * Hook for using an external bloc store
package/dist/index.es.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { BlacAdapter as v, generateUUID as h, Blac as w } from "@blac/core";
2
2
  import { useRef as u, useMemo as b, useEffect as M, useSyncExternalStore as U } from "react";
3
3
  function P(n, e) {
4
- const s = u(0);
5
- s.current++;
4
+ const m = u(0);
5
+ m.current++;
6
6
  const f = u({}), r = b(() => new v(
7
7
  {
8
8
  componentRef: f,
@@ -27,11 +27,11 @@ function P(n, e) {
27
27
  onUnmount: e == null ? void 0 : e.onUnmount
28
28
  }, (e == null ? void 0 : e.props) !== void 0 && r.updateProps(e.props);
29
29
  }, [e == null ? void 0 : e.props, e == null ? void 0 : e.id, e == null ? void 0 : e.dependencies, e == null ? void 0 : e.onMount, e == null ? void 0 : e.onUnmount]);
30
- const I = u(0);
31
- M(() => (I.current++, r.mount(), () => {
30
+ const x = u(0);
31
+ M(() => (x.current++, r.mount(), () => {
32
32
  r.unmount();
33
33
  }), [r.blocInstance]);
34
- const x = u(0), c = b(() => (x.current++, (l) => {
34
+ const B = u(0), c = b(() => (B.current++, (l) => {
35
35
  const g = r.createSubscription({
36
36
  onChange: () => {
37
37
  l();
@@ -40,7 +40,7 @@ function P(n, e) {
40
40
  return () => {
41
41
  g();
42
42
  };
43
- }), [r.blocInstance]), a = u(0), d = u(0), m = U(
43
+ }), [r.blocInstance]), a = u(0), d = u(0), s = U(
44
44
  c,
45
45
  // Get snapshot
46
46
  () => (a.current++, r.blocInstance.state),
@@ -49,23 +49,23 @@ function P(n, e) {
49
49
  const l = r.blocInstance;
50
50
  return d.current++, l.state;
51
51
  }
52
- ), S = u(0), y = b(() => (S.current++, r.getProxyState(m)), [m]), B = u(0), C = b(() => (B.current++, r.getProxyBlocInstance()), [r.blocInstance]);
52
+ ), S = u(0), I = b(() => (S.current++, r.getProxyState(s)), [s]), y = u(0), C = b(() => (y.current++, r.getProxyBlocInstance()), [r.blocInstance]);
53
53
  return M(() => {
54
54
  r.updateLastNotified(f.current);
55
- }), [y, C];
55
+ }), [I, C];
56
56
  }
57
57
  function K(n, e = {}) {
58
- const s = u(`external-${h()}`), f = u(/* @__PURE__ */ new Set()), r = u(/* @__PURE__ */ new Set()), t = u(null), I = b(() => {
58
+ const m = u(`external-${h()}`), f = u(/* @__PURE__ */ new Set()), r = u(/* @__PURE__ */ new Set()), t = u(null), x = b(() => {
59
59
  const c = w.getInstance();
60
60
  if (n.constructor.isolated || n.isolated) {
61
- const d = new n(e == null ? void 0 : e.props), m = (e == null ? void 0 : e.id) || `${n.name}_${h()}`;
62
- return d._updateId(m), c.activateBloc(d), d;
61
+ const d = new n(e == null ? void 0 : e.props), s = (e == null ? void 0 : e.id) || `${n.name}_${h()}`;
62
+ return d._updateId(s), c.activateBloc(d), d;
63
63
  }
64
64
  return c.getBloc(n, {
65
65
  id: e == null ? void 0 : e.id,
66
66
  props: e == null ? void 0 : e.props
67
67
  });
68
- }, [n, e == null ? void 0 : e.id]), x = b(
68
+ }, [n, e == null ? void 0 : e.id]), B = b(
69
69
  () => ({
70
70
  getSnapshot: () => {
71
71
  const c = t.current;
@@ -76,15 +76,15 @@ function K(n, e = {}) {
76
76
  if (!a)
77
77
  return () => {
78
78
  };
79
- const d = (S, y) => {
79
+ const d = (S, I) => {
80
80
  try {
81
- f.current.clear(), r.current.clear(), e.selector && a && e.selector(S, y, a), c.length > 0 ? c(S) : c();
82
- } catch (B) {
83
- console.error("Listener error in useExternalBlocStore:", B);
81
+ f.current.clear(), r.current.clear(), e.selector && a && e.selector(S, I, a), c.length > 0 ? c(S) : c();
82
+ } catch (y) {
83
+ console.error("Listener error in useExternalBlocStore:", y);
84
84
  }
85
85
  };
86
86
  return a._observer.subscribe({
87
- id: s.current,
87
+ id: m.current,
88
88
  fn: d
89
89
  });
90
90
  },
@@ -95,16 +95,17 @@ function K(n, e = {}) {
95
95
  }),
96
96
  []
97
97
  );
98
- return t.current = I, {
99
- externalStore: x,
98
+ return t.current = x, {
99
+ externalStore: B,
100
100
  instance: t,
101
101
  usedKeys: f,
102
102
  usedClassPropKeys: r,
103
- rid: s.current
103
+ rid: m.current
104
104
  };
105
105
  }
106
106
  export {
107
107
  P as useBloc,
108
+ P as useBlocNext,
108
109
  K as useExternalBlocStore
109
110
  };
110
111
  //# sourceMappingURL=index.es.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blac/react",
3
- "version": "2.0.0-rc-11",
3
+ "version": "2.0.0-rc-13",
4
4
  "license": "MIT",
5
5
  "author": "Brendan Mullins <jsnanigans@gmail.com>",
6
6
  "main": "dist/index.cjs.js",
@@ -30,7 +30,7 @@
30
30
  "@types/react-dom": "^18.0.0 || ^19.0.0",
31
31
  "react": "^18.0.0 || ^19.0.0",
32
32
  "react-dom": "^18.0.0 || ^19.0.0",
33
- "@blac/core": "2.0.0-rc-11"
33
+ "@blac/core": "2.0.0-rc-13"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@types/react": {
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { default as useBloc } from './useBloc';
2
+ export { default as useBlocNext } from './useBloc';
2
3
  export { default as useExternalBlocStore } from './useExternalBlocStore';