Angular bindings for Coexist: an environment provider and
inject*helpers that expose a Coexist app (or a worker-hosted app) as Angular signals.
pnpm add @coexist/angular @coexist/coreShips as ESM only: your project needs "type": "module" (or .mjs/.mts) and Node.js >=22.12.0 or a modern bundler.
@coexist/core is a peer dependency: this package shares the app runtime you install, rather than bundling a second copy of it.
Peer dependency: @angular/core >=17 <23.
Register the app with provideCoexist(app) during bootstrap, then inject the module and signals inside components.
import { Component } from "@angular/core";
import { bootstrapApplication } from "@angular/platform-browser";
import { injectModule, injectSignal, provideCoexist } from "@coexist/angular";
@Component({
selector: "counter-view",
template: `<button (click)="counter.increase()">{{ count() }}</button>`,
})
class CounterView {
readonly counter = injectModule(Counter);
readonly count = injectSignal(Counter, (module) => module.count);
}
bootstrapApplication(CounterView, {
providers: [provideCoexist(app)],
});injectSignal returns a read-only Angular Signal<T> — call it (count()) in the template.
| Function | Returns | Description |
|---|---|---|
provideCoexist(app) |
EnvironmentProviders |
Register the app for DI. |
injectCoexistApp() |
App |
Inject the app. |
injectModule(token) |
T |
The bound module facade. No subscription. |
injectSignal(fn, opts?) |
Signal<T> |
Signal for fn(app). |
injectSignal(token, fn, opts?) |
Signal<TValue> |
Signal for fn(module, app). |
injectModule resolves the module and nothing else — it creates no signal, and a facade read is not tracked by Angular's reactivity. Reading state off it in a template (injectModule(Counter).count) renders correctly once and then goes stale, silently. Call actions through the facade; render state through injectSignal.
injectSignal accepts { equals } (defaults to Object.is) and unsubscribes automatically through DestroyRef. It must run in an injection context.
injectWorkerSignal reads the client snapshot synchronously, so it throws until the host's first snapshot arrives. Await client.ready before bootstrapping components that use it; injectWorkerModule is safe at any time.
import { Component } from "@angular/core";
import { bootstrapApplication } from "@angular/platform-browser";
import { injectWorkerModule, injectWorkerSignal, provideWorkerClient } from "@coexist/angular";
type CounterState = { readonly counter: { readonly count: number } };
@Component({
selector: "counter-view",
template: `<button (click)="counter.increase()">{{ count() }}</button>`,
})
class WorkerCounterView {
readonly counter = injectWorkerModule<Counter>("counter");
readonly count = injectWorkerSignal((state) => (state as CounterState).counter.count);
}
bootstrapApplication(WorkerCounterView, {
providers: [provideWorkerClient(client)],
});provideWorkerClient(client)→EnvironmentProviders.injectWorkerClient()→ theWorkerClient.injectWorkerModule<T>(name)→ anAsyncMethodProxy<T>.injectWorkerSignal(fn, opts?)→ aSignal<T>of worker state.
provideCoexist, provideWorkerClient, the COEXIST_APP / COEXIST_WORKER_CLIENT injection tokens, injectCoexistApp, injectModule, injectSignal, injectWorkerClient, injectWorkerModule, injectWorkerSignal, and the InjectSignalOptions, AppSelector, ModuleSelector types.
MIT © Coaction