@encatch/event-publisher
v1.1.0
Published
Internal package for publishing and subscribing to form events across the Encatch ecosystem.
Readme
@encatch/event-publisher
Internal package for publishing and subscribing to form events across the Encatch ecosystem.
Installation
This is an internal package. Add it to your package dependencies:
{
"dependencies": {
"@encatch/event-publisher": "workspace:*"
}
}Usage
import { formEventPublisher } from '@encatch/event-publisher';
// Subscribe to form submit events
const unsubscribe = formEventPublisher.subscribe('form:submit', (payload) => {
console.log('Form submitted:', payload);
});
// Subscribe with form ID filter
formEventPublisher.subscribe(
'form:submit',
(payload) => {
console.log('Specific form submitted:', payload);
},
{ formId: 'specific-form-id' }
);
// Publish an event
formEventPublisher.publish('form:submit', {
feedbackConfigurationId: 'form-id',
response: { /* form data */ },
timestamp: Date.now()
});
// Unsubscribe when done
unsubscribe();API
Types
FormEventType: Event types ('form:show', 'form:submit', 'form:close', etc.)FormEventPayload: Payload types for each eventFormIdFilter: Filter for specific form IDsSubscriptionOptions: Options for subscriptions
Methods
publish<T>(eventType: T, payload: FormEventPayload[T], options?): Publish an eventsubscribe<T>(eventType: T, handler: Function, options?): Subscribe to eventssubscribeAll(handler: Function, options?): Subscribe to all event typesgetSubscriptionCount(eventType?): Get active subscription countclearSubscriptions(eventType?): Clear subscriptions
