publisher
Installation
SKILL.md
Publisher
Installation: If not already installed, add the package with pnpm add @efesto-cloud/publisher.
Use this skill when you need event broadcasting without stored state.
Quick Rule
Publisher: emit events withnotify(...)to current subscribers.- No state: if you need
get/set, use Observable instead.
Procedure
- Create
new PublisherImpl<Args>()with typed tuple args. - Register listeners with
subscribe(...)and keep the cleanup function. - Emit events via
notify(...)and cleanup with returned unsubscribe orunsubscribeAll().
Common Mistakes
- Using Publisher as a state container.
- Ignoring returned unsubscribe function.
- Emitting args that do not match the tuple type.
Tiny Example
const bus = new PublisherImpl<[string, number]>();
const off = bus.subscribe((event, code) => console.log(event, code));
bus.notify("saved", 200);
off();
Simplified Interface
type Subscriber<ARGS extends unknown[]> = (...args: ARGS) => void;
type Unsubscribe = () => void;
interface IPublisher<ARGS extends unknown[]> {
size: number;
subscribe(s: Subscriber<ARGS>): Unsubscribe;
unsubscribe(id: number): void;
notify(...args: ARGS): void;
unsubscribeAll(): void;
}
Related skills
More from efesto-cloud/skills
persistence
>
18population
>
17type-enum-dict
|
17value-object
|
17usecase
>
16entity
Create or modify domain entities using the @efesto-cloud/entity package. Use this skill whenever the user asks to add a new entity, update an existing entity, add properties or methods to an entity, or work on the entity/dto layer. Trigger when the user says things like "create a Foo entity", "add a field to Bar", "I need a new domain object", or "add entity X". Also trigger for DTO creation or modification.
16