@hyperfrontend/features/hosteeHostee
Hostee-side SDK for feature apps — feature initialization, contract declaration, and lifecycle.
import { createFeature } from '@hyperfrontend/features/hostee'
const feature = createFeature({
name: 'clock',
contract: {
emitted: [{ type: 'tick' }],
accepted: [{ type: 'set-timezone' }],
},
})
await feature.ready()
feature.on('set-timezone', ({ tz }) => render(tz))
setInterval(() => feature.send('tick', Date.now()), 1000)
API
| Export | Purpose |
|---|---|
createFeature | Connect a feature app to its host; returns send/on/ready/close. |
FeatureHandle | Type of the handle returned by createFeature. |
ready() resolves once the host connection is established. send emits a contract action to the host; on subscribes to host messages and the open/close/error lifecycle events. close disconnects from the host.
API Reference
ƒ Functions
Initializes a feature app on the hostee side and waits for the host connection.
Creates a nexus broker for the feature, resolves the host window, and returns a handle for messaging and lifecycle.
Creates a nexus broker for the feature, resolves the host window, and returns a handle for messaging and lifecycle.
Parameters
| Name | Type | Description |
|---|---|---|
§options | FeatureOptions | Feature name and contract. |
Returns
FeatureHandleA handle exposing
send, on, ready, and close.Example
Initializing a clock feature
const feature = createFeature({ name: 'clock', contract })
feature.ready().then(() => feature.send('timeUpdated', { time: Date.now() }))
feature.on('setTimezone', (data) => console.log(data))◈ Interfaces
Description of a single action a feature can emit or accept.
Structurally compatible with nexus's channel contract action shape so the same contract can drive both messaging and the shell type generator.
Structurally compatible with nexus's channel contract action shape so the same contract can drive both messaging and the shell type generator.
Properties
§
respondsWith?:string— When this action is used as a request, the type of the action in the other direction that answers it.
The set of actions a feature emits to, and accepts from, its counterpart.
This is the same shape the on-disk
This is the same shape the on-disk
*.contract.json files and the shell generator consume.Options accepted by the hostee-side feature factory.
◆ Types
Answers one request type; may return the response value directly or a promise of it.
type RequestHandler = (data: unknown) => unknown