PanClient
src/components/pan-client.mjs
PanClient provides a clean, promise-based API for publish/subscribe messaging
and request/reply patterns. It handles the low-level CustomEvent details and
provides convenient methods for common operations.
and request/reply patterns. It handles the low-level CustomEvent details and
provides convenient methods for common operations.
Class: PanClient
PanClient provides a clean, promise-based API for publish/subscribe messaging
and request/reply patterns. It handles the low-level CustomEvent details and
provides convenient methods for common operations.
/
/**
/
/**
/
/**
/
/**
/
/**
PAN Client - Simplified API for PAN bus interaction
Provides a clean interface for:
- Publishing messages
- Subscribing to topics (with wildcard support)
- Request/reply pattern with automatic correlation
- Retained message support
- Automatic cleanup with AbortSignal
and request/reply patterns. It handles the low-level CustomEvent details and
provides convenient methods for common operations.
/
/**
/
/**
/
/**
/
/**
/
/**
PAN Client - Simplified API for PAN bus interaction
Provides a clean interface for:
- Publishing messages
- Subscribing to topics (with wildcard support)
- Request/reply pattern with automatic correlation
- Retained message support
- Automatic cleanup with AbortSignal
Examples
// Basic usage
import { PanClient } from './pan-client.mjs';
const client = new PanClient();
await client.ready();
// Publish a message
client.publish({
topic: 'users.list.state',
data: { users: [...] },
retain: true
});
// Subscribe to messages
const unsubscribe = client.subscribe('users.*', (msg) => {
console.log('Received:', msg.topic, msg.data);
});
// Request/reply
const response = await client.request('users.get', { id: 123 });
console.log('User:', response.data);
/
/**
// Create client for the document
const client = new PanClient();
// Or create client for a specific element
const myElement = document.querySelector('#my-component');
const client = new PanClient(myElement);