Skip to content

API reference / @jsprismarine/content / BehaviorRegistry

Class: BehaviorRegistry<H> ​

Defined in: packages/content/src/behaviors.ts:62

The behaviors a domain implements and the identifiers they attach to.

Attachment order is the order BehaviorRegistry.attach ran, and that is the order the handlers dispatch in. Attaching one behavior to the same identifier twice binds it once, at its first position.

Type Parameters ​

H ​

H extends HookSignatures<H>

Constructors ​

Constructor ​

new BehaviorRegistry<H>(): BehaviorRegistry<H>

Returns ​

BehaviorRegistry<H>

Methods ​

attach() ​

attach(behaviorName, selector): void

Defined in: packages/content/src/behaviors.ts:83

Attaches a registered behavior to every type the selector matches.

Parameters ​

behaviorName ​

string

selector ​

BehaviorSelector

Returns ​

void

Throws ​

When no behavior is registered under the name.


bind() ​

bind(context): readonly BoundBehavior<H>[]

Defined in: packages/content/src/behaviors.ts:106

Builds the handlers every attached behavior contributes to one type, in attachment order.

Parameters ​

context ​

BindContext

Returns ​

readonly BoundBehavior<H>[]

Throws ​

When a behavior returns a hook it does not declare.


has() ​

has(name): boolean

Defined in: packages/content/src/behaviors.ts:91

Whether a behavior is registered under the name.

Parameters ​

name ​

string

Returns ​

boolean


names() ​

names(): readonly string[]

Defined in: packages/content/src/behaviors.ts:96

Every registered behavior name, in registration order.

Returns ​

readonly string[]


register() ​

register(behavior): void

Defined in: packages/content/src/behaviors.ts:71

Adds one behavior.

Parameters ​

behavior ​

Behavior<H>

Returns ​

void

Throws ​

When the name is already registered.