@blac/core 2.0.0-rc-5 → 2.0.0-rc-6

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/src/types.ts CHANGED
@@ -54,8 +54,31 @@ export type BlocConstructorParameters<B extends BlocBase<any>> =
54
54
  BlocConstructor<B> extends new (...args: infer P) => B ? P : never;
55
55
 
56
56
  /**
57
- * Represents a function type for determining hook dependencies based on state changes
58
- * @template B - The BlocGeneric type
57
+ * Base interface for all Bloc events
58
+ * Events must be objects with a constructor to enable proper type matching
59
+ */
60
+ export interface BlocEvent {
61
+ readonly type?: string;
62
+ readonly timestamp?: number;
63
+ }
64
+
65
+ /**
66
+ * Enhanced constraint for Bloc events - must be objects with proper constructor
67
+ */
68
+ export type BlocEventConstraint = BlocEvent & object;
69
+
70
+ /**
71
+ * Error boundary interface for Bloc error handling
72
+ */
73
+ export interface BlocErrorBoundary<S, A extends BlocEventConstraint> {
74
+ onError: (error: Error, event: A, currentState: S, bloc: { name: string; id: string }) => void | Promise<void>;
75
+ shouldRethrow?: (error: Error, event: A) => boolean;
76
+ }
77
+
78
+ /**
79
+ * Function type for determining dependencies that trigger re-renders
80
+ * @template S The state type
81
+ * @returns Array of dependency arrays - if any dependency in any array changes, a re-render is triggered
59
82
  */
60
83
  export type BlocHookDependencyArrayFn<S> = (
61
84
  newState: S
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Cross-platform UUID v4 generator that works in all environments including React Native/Hermes
3
+ * Falls back to crypto.randomUUID() when available, otherwise uses Math.random()
4
+ */
5
+
6
+ /**
7
+ * Generates a UUID v4 string compatible with all JavaScript environments
8
+ * @returns A UUID v4 string in the format xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
9
+ */
10
+ export function generateUUID(): string {
11
+ // Try to use crypto.randomUUID() if available (Node.js 16+, modern browsers)
12
+ if (typeof crypto !== 'undefined' && crypto.randomUUID) {
13
+ return crypto.randomUUID();
14
+ }
15
+
16
+ // Fallback implementation for React Native/Hermes and older environments
17
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
18
+ const r = Math.random() * 16 | 0;
19
+ const v = c === 'x' ? r : (r & 0x3 | 0x8);
20
+ return v.toString(16);
21
+ });
22
+ }