@hyperfrontend/features/hostee

Hostee

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

ExportPurpose
createFeatureConnect a feature app to its host; returns send/on/ready/close.
FeatureHandleType 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

§function

createFeature(options: FeatureOptions): FeatureHandle

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.

Parameters

NameTypeDescription
§options
FeatureOptions
Feature name and contract.

Returns

FeatureHandle
A 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

§interface

FeatureHandle

Public handle returned by the hostee-side feature factory.

Properties