react-waitlist
Version:
A customizable waitlist form component for React applications
59 lines (58 loc) • 1.83 kB
TypeScript
/**
* Types of events that can be emitted by the waitlist component
*/
export type WaitlistEventType = 'field_focus' | 'submit' | 'success' | 'error' | 'security';
/**
* Data structure for events
*/
export interface WaitlistEventData {
/** Type of event */
type: WaitlistEventType;
/** Timestamp of the event */
timestamp: string;
/** Field name (for field_focus events) */
field?: string;
/** Form data (for submit, success, error events) */
formData?: Record<string, any>;
/** Response from API (for success events) */
response?: any;
/** Error information (for error events) */
error?: {
message: string;
code?: string;
};
/** Security type (for security events) */
securityType?: string;
/** Security details (for security events) */
details?: Record<string, any>;
}
/**
* Event handler function type
*/
export type WaitlistEventHandler = (data: WaitlistEventData) => void;
/**
* Event bus for handling waitlist events
*/
export declare class EventBus {
private handlers;
/**
* Subscribe to an event
* @param type Type of event to subscribe to
* @param handler Function to call when the event occurs
* @returns Function to unsubscribe
*/
subscribe(type: WaitlistEventType, handler: WaitlistEventHandler): () => void;
/**
* Subscribe to multiple event types
* @param types Array of event types to subscribe to
* @param handler Function to call when any of the events occur
* @returns Function to unsubscribe from all events
*/
subscribeToMany(types: WaitlistEventType[], handler: WaitlistEventHandler): () => void;
/**
* Emit an event
* @param data Event data
*/
emit(data: WaitlistEventData): void;
}
export declare const eventBus: EventBus;