Events
Modules communicate through a versioned event bus rather than calling each other directly. Your module declares what it publishes and subscribes to in the manifest; the platform validates those declarations against a catalog.
Declare in the manifest
json
"events": {
"publishes": [
{ "name": "cafm.work-order.created", "version": "1.0.0" }
],
"subscribes": [
{ "name": "building.alarm.triggered", "version": "1.0.0" }
]
}Validate against the catalog
bash
npx tv-sdk check-eventsThis checks that:
- Every event you subscribe to exists in the platform catalog.
- Every event you publish either exists, or comes with its own schema declaration (a new module event).
- Versions are compatible.
A green check-events means your event wiring matches the platform's contract. If it's red, the message tells you which event and why.
Publish + subscribe at runtime
ts
import { usePlatformContext } from '@tv/extension-sdk/react';
function useWorkOrderEvents() {
const { events } = usePlatformContext();
// publish
const announce = (wo: WorkOrder) =>
events.publish('cafm.work-order.created', {
version: '1.0.0',
payload: { id: wo.id, buildingId: wo.buildingId },
});
// subscribe
events.subscribe('building.alarm.triggered', (msg) => {
// react to the alarm
});
return { announce };
}Versioning
Event names are namespaced (<module>.<entity>.<action>) and carry a semver version. Bumping a payload's shape in a breaking way means a new major on that event — consumers pin the version they understand, so you can evolve without breaking them.
→ Next: Testing