@blac/react 2.0.0-rc.6 → 2.0.0-rc.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/dist/index.d.cts CHANGED
@@ -1,154 +1,12 @@
1
- import { AnyObject, BlocConstructor, ExtractState, StateContainer } from "@blac/core";
2
- import { RefObject } from "react";
3
-
4
- //#region src/types.d.ts
5
-
6
1
  /**
7
- * Configuration options for the useBloc hook
2
+ * React Integration
8
3
  *
9
- * @template TBloc - The StateContainer type
10
- *
11
- * @example
12
- * ```tsx
13
- * const [state, bloc] = useBloc(CounterBloc, {
14
- * staticProps: { initialCount: 0 },
15
- * dependencies: (state) => [state.count],
16
- * onMount: (bloc) => console.log('Mounted'),
17
- * });
18
- * ```
19
- */
20
- interface UseBlocOptions<TBloc extends StateContainer<AnyObject>> {
21
- /**
22
- * Static props to pass to the Bloc constructor
23
- * Type should match the constructor's first parameter
24
- */
25
- staticProps?: AnyObject;
26
- /**
27
- * Custom instance ID for shared blocs
28
- * - For isolated blocs, each useBloc call gets its own instance
29
- * - For shared blocs, the same instanceId will share the same bloc instance
30
- */
31
- instanceId?: string;
32
- /**
33
- * Manual dependency tracking function
34
- * - When provided, automatic proxy tracking is disabled
35
- * - Component only re-renders when the returned values change (shallow equality)
36
- *
37
- * @param state - Current state of the bloc
38
- * @param bloc - The bloc instance
39
- * @returns Array of values to track
40
- */
41
- dependencies?: (state: ExtractState<TBloc>, bloc: TBloc) => unknown[];
42
- /**
43
- * Control automatic dependency tracking (default: true)
44
- * - true: Automatically track accessed properties via Proxy
45
- * - false: Disable tracking, all state changes trigger re-render
46
- * - Ignored when `dependencies` option is provided
47
- *
48
- * @default true
49
- */
50
- autoTrack?: boolean;
51
- /**
52
- * Callback invoked when the component mounts
53
- *
54
- * @param bloc - The bloc instance
55
- */
56
- onMount?: (bloc: TBloc) => void;
57
- /**
58
- * Callback invoked when the component unmounts
59
- *
60
- * @param bloc - The bloc instance
61
- */
62
- onUnmount?: (bloc: TBloc) => void;
63
- }
64
- /**
65
- * Return type of the useBloc hook
66
- *
67
- * @template TBloc - The StateContainer type
68
- *
69
- * @returns A tuple containing:
70
- * - [0]: The current state (may be a Proxy for tracking)
71
- * - [1]: The bloc instance with methods
72
- * - [2]: Component ref (internal use only)
73
- */
74
- type UseBlocReturn<TBloc extends StateContainer<AnyObject>> = [ExtractState<TBloc>, TBloc, RefObject<ComponentRef>];
75
- /**
76
- * @internal
77
- * Component reference object for internal tracking
78
- * Used to persist instance IDs across React Strict Mode remounts
79
- */
80
- type ComponentRef = {
81
- __blocInstanceId?: string;
82
- __bridge?: any;
83
- };
84
- //#endregion
85
- //#region src/useBloc.d.ts
86
- /**
87
- * Lifecycle: INITIAL MOUNT
88
- * 1. useMemo runs once - creates bloc, subscribeFn, getSnapshotFn
89
- * 2. useSyncExternalStore calls getSnapshotFn (1st time) - lazy creates tracker, starts tracking, returns proxy
90
- * 3. Component renders - proxy tracks property accesses
91
- * 4. useSyncExternalStore calls getSnapshotFn (2nd time) - captures tracked paths, starts new tracking, returns proxy
92
- * 5. useSyncExternalStore calls subscribeFn - sets up state change listener
93
- *
94
- * Lifecycle: STATE CHANGE
95
- * 1. Bloc state changes
96
- * 2. subscribeFn callback checks hasChanges() - only re-renders if tracked paths changed
97
- * 3. If re-render: getSnapshotFn captures previous paths, starts tracking, returns proxy
98
- *
99
- * Lifecycle: RE-RENDER (parent re-render)
100
- * 1. useMemo returns cached values (same bloc, subscribeFn, getSnapshotFn)
101
- * 2. useSyncExternalStore calls getSnapshotFn - captures paths, starts tracking, returns proxy
102
- */
103
- declare function useBloc<TBloc extends StateContainer<AnyObject>>(BlocClass: BlocConstructor<TBloc>, options?: UseBlocOptions<TBloc>): UseBlocReturn<TBloc>;
104
- //#endregion
105
- //#region src/useBlocActions.d.ts
106
- /**
107
- * Configuration options for the useBlocActions hook
108
- *
109
- * @template TBloc - The StateContainer type
110
- */
111
- interface UseBlocActionsOptions<TBloc extends StateContainer<AnyObject>> {
112
- /**
113
- * Static props to pass to the Bloc constructor
114
- * Type should match the constructor's first parameter
115
- */
116
- staticProps?: AnyObject;
117
- /**
118
- * Custom instance ID for shared blocs
119
- * - For isolated blocs, each useBlocActions call gets its own instance
120
- * - For shared blocs, the same instanceId will share the same bloc instance
121
- */
122
- instanceId?: string;
123
- /**
124
- * Callback invoked when the component mounts
125
- *
126
- * @param bloc - The bloc instance
127
- */
128
- onMount?: (bloc: TBloc) => void;
129
- /**
130
- * Callback invoked when the component unmounts
131
- *
132
- * @param bloc - The bloc instance
133
- */
134
- onUnmount?: (bloc: TBloc) => void;
135
- }
136
- /**
137
- * React hook for accessing bloc instance without state subscription.
138
- * Use this when you only need to call bloc methods/actions without reading state.
139
- *
140
- * Benefits over useBloc:
141
- * - No state subscription overhead
142
- * - No proxy tracking
143
- * - Component never re-renders due to bloc state changes
144
- * - Lighter weight for action-only components
145
- *
146
- * @template TBloc - The StateContainer type
147
- * @param BlocClass - The bloc class constructor
148
- * @param options - Optional configuration
149
- * @returns The bloc instance
4
+ * Clean integration between React and StateContainer architecture.
5
+ * Constructor-based API with automatic type inference.
6
+ * Supports concurrent (useSyncExternalStore) mode for optimal performance.
150
7
  */
151
- declare function useBlocActions<TBloc extends StateContainer<AnyObject>>(BlocClass: BlocConstructor<TBloc>, options?: UseBlocActionsOptions<TBloc>): TBloc;
152
- //#endregion
153
- export { type UseBlocActionsOptions, type UseBlocOptions, type UseBlocReturn, useBloc, useBlocActions };
154
- //# sourceMappingURL=index.d.cts.map
8
+ export { useBloc } from './useBloc';
9
+ export { useBlocActions } from './useBlocActions';
10
+ export type { UseBlocOptions, UseBlocReturn } from './types';
11
+ export type { UseBlocActionsOptions } from './useBlocActions';
12
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,154 +1,12 @@
1
- import { RefObject } from "react";
2
- import { AnyObject, BlocConstructor, ExtractState, StateContainer } from "@blac/core";
3
-
4
- //#region src/types.d.ts
5
-
6
1
  /**
7
- * Configuration options for the useBloc hook
2
+ * React Integration
8
3
  *
9
- * @template TBloc - The StateContainer type
10
- *
11
- * @example
12
- * ```tsx
13
- * const [state, bloc] = useBloc(CounterBloc, {
14
- * staticProps: { initialCount: 0 },
15
- * dependencies: (state) => [state.count],
16
- * onMount: (bloc) => console.log('Mounted'),
17
- * });
18
- * ```
19
- */
20
- interface UseBlocOptions<TBloc extends StateContainer<AnyObject>> {
21
- /**
22
- * Static props to pass to the Bloc constructor
23
- * Type should match the constructor's first parameter
24
- */
25
- staticProps?: AnyObject;
26
- /**
27
- * Custom instance ID for shared blocs
28
- * - For isolated blocs, each useBloc call gets its own instance
29
- * - For shared blocs, the same instanceId will share the same bloc instance
30
- */
31
- instanceId?: string;
32
- /**
33
- * Manual dependency tracking function
34
- * - When provided, automatic proxy tracking is disabled
35
- * - Component only re-renders when the returned values change (shallow equality)
36
- *
37
- * @param state - Current state of the bloc
38
- * @param bloc - The bloc instance
39
- * @returns Array of values to track
40
- */
41
- dependencies?: (state: ExtractState<TBloc>, bloc: TBloc) => unknown[];
42
- /**
43
- * Control automatic dependency tracking (default: true)
44
- * - true: Automatically track accessed properties via Proxy
45
- * - false: Disable tracking, all state changes trigger re-render
46
- * - Ignored when `dependencies` option is provided
47
- *
48
- * @default true
49
- */
50
- autoTrack?: boolean;
51
- /**
52
- * Callback invoked when the component mounts
53
- *
54
- * @param bloc - The bloc instance
55
- */
56
- onMount?: (bloc: TBloc) => void;
57
- /**
58
- * Callback invoked when the component unmounts
59
- *
60
- * @param bloc - The bloc instance
61
- */
62
- onUnmount?: (bloc: TBloc) => void;
63
- }
64
- /**
65
- * Return type of the useBloc hook
66
- *
67
- * @template TBloc - The StateContainer type
68
- *
69
- * @returns A tuple containing:
70
- * - [0]: The current state (may be a Proxy for tracking)
71
- * - [1]: The bloc instance with methods
72
- * - [2]: Component ref (internal use only)
73
- */
74
- type UseBlocReturn<TBloc extends StateContainer<AnyObject>> = [ExtractState<TBloc>, TBloc, RefObject<ComponentRef>];
75
- /**
76
- * @internal
77
- * Component reference object for internal tracking
78
- * Used to persist instance IDs across React Strict Mode remounts
79
- */
80
- type ComponentRef = {
81
- __blocInstanceId?: string;
82
- __bridge?: any;
83
- };
84
- //#endregion
85
- //#region src/useBloc.d.ts
86
- /**
87
- * Lifecycle: INITIAL MOUNT
88
- * 1. useMemo runs once - creates bloc, subscribeFn, getSnapshotFn
89
- * 2. useSyncExternalStore calls getSnapshotFn (1st time) - lazy creates tracker, starts tracking, returns proxy
90
- * 3. Component renders - proxy tracks property accesses
91
- * 4. useSyncExternalStore calls getSnapshotFn (2nd time) - captures tracked paths, starts new tracking, returns proxy
92
- * 5. useSyncExternalStore calls subscribeFn - sets up state change listener
93
- *
94
- * Lifecycle: STATE CHANGE
95
- * 1. Bloc state changes
96
- * 2. subscribeFn callback checks hasChanges() - only re-renders if tracked paths changed
97
- * 3. If re-render: getSnapshotFn captures previous paths, starts tracking, returns proxy
98
- *
99
- * Lifecycle: RE-RENDER (parent re-render)
100
- * 1. useMemo returns cached values (same bloc, subscribeFn, getSnapshotFn)
101
- * 2. useSyncExternalStore calls getSnapshotFn - captures paths, starts tracking, returns proxy
102
- */
103
- declare function useBloc<TBloc extends StateContainer<AnyObject>>(BlocClass: BlocConstructor<TBloc>, options?: UseBlocOptions<TBloc>): UseBlocReturn<TBloc>;
104
- //#endregion
105
- //#region src/useBlocActions.d.ts
106
- /**
107
- * Configuration options for the useBlocActions hook
108
- *
109
- * @template TBloc - The StateContainer type
110
- */
111
- interface UseBlocActionsOptions<TBloc extends StateContainer<AnyObject>> {
112
- /**
113
- * Static props to pass to the Bloc constructor
114
- * Type should match the constructor's first parameter
115
- */
116
- staticProps?: AnyObject;
117
- /**
118
- * Custom instance ID for shared blocs
119
- * - For isolated blocs, each useBlocActions call gets its own instance
120
- * - For shared blocs, the same instanceId will share the same bloc instance
121
- */
122
- instanceId?: string;
123
- /**
124
- * Callback invoked when the component mounts
125
- *
126
- * @param bloc - The bloc instance
127
- */
128
- onMount?: (bloc: TBloc) => void;
129
- /**
130
- * Callback invoked when the component unmounts
131
- *
132
- * @param bloc - The bloc instance
133
- */
134
- onUnmount?: (bloc: TBloc) => void;
135
- }
136
- /**
137
- * React hook for accessing bloc instance without state subscription.
138
- * Use this when you only need to call bloc methods/actions without reading state.
139
- *
140
- * Benefits over useBloc:
141
- * - No state subscription overhead
142
- * - No proxy tracking
143
- * - Component never re-renders due to bloc state changes
144
- * - Lighter weight for action-only components
145
- *
146
- * @template TBloc - The StateContainer type
147
- * @param BlocClass - The bloc class constructor
148
- * @param options - Optional configuration
149
- * @returns The bloc instance
4
+ * Clean integration between React and StateContainer architecture.
5
+ * Constructor-based API with automatic type inference.
6
+ * Supports concurrent (useSyncExternalStore) mode for optimal performance.
150
7
  */
151
- declare function useBlocActions<TBloc extends StateContainer<AnyObject>>(BlocClass: BlocConstructor<TBloc>, options?: UseBlocActionsOptions<TBloc>): TBloc;
152
- //#endregion
153
- export { type UseBlocActionsOptions, type UseBlocOptions, type UseBlocReturn, useBloc, useBlocActions };
8
+ export { useBloc } from './useBloc';
9
+ export { useBlocActions } from './useBlocActions';
10
+ export type { UseBlocOptions, UseBlocReturn } from './types';
11
+ export type { UseBlocActionsOptions } from './useBlocActions';
154
12
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7D,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC"}