Skip to content

API reference / @jsprismarine/content / Registry

Class: Registry<T> ​

Defined in: packages/content/src/registry.ts:73

A named table of values keyed by namespaced identifier, with a dense numeric id per entry.

Ids run from 0 in insertion order and are positional, not persistent: a rebuild that inserts the same keys in the same order reproduces every id, and a rebuild that reorders or drops keys renumbers from 0. Persist keys, not ids, and hold a Holder rather than an id across a content reload.

The built key and value lists are frozen. Nothing writes to a registry except Registry.rebuild, which replaces the contents whole.

Type Parameters ​

T ​

T

Implements ​

  • Iterable<readonly [string, T]>

Constructors ​

Constructor ​

new Registry<T>(name): Registry<T>

Defined in: packages/content/src/registry.ts:81

Parameters ​

name ​

string

The registry's name, such as blocks; it appears in holders and diagnostics.

Returns ​

Registry<T>

Properties ​

name ​

readonly name: string

Defined in: packages/content/src/registry.ts:81

The registry's name, such as blocks; it appears in holders and diagnostics.

Accessors ​

generation ​

Get Signature ​

get generation(): number

Defined in: packages/content/src/registry.ts:84

How many builds have run, so callers can tell a reload happened.

Returns ​

number


size ​

Get Signature ​

get size(): number

Defined in: packages/content/src/registry.ts:89

How many entries the current build holds.

Returns ​

number

Methods ​

[iterator]() ​

[iterator](): IterableIterator<readonly [string, T]>

Defined in: packages/content/src/registry.ts:178

Iterates the entries in id order.

Returns ​

IterableIterator<readonly [string, T]>

Implementation of ​

Iterable.[iterator]


at() ​

at(id): T | undefined

Defined in: packages/content/src/registry.ts:126

The value at an id, or undefined when the id is out of range.

Parameters ​

id ​

number

Returns ​

T | undefined


entries() ​

entries(): IterableIterator<readonly [string, T]>

Defined in: packages/content/src/registry.ts:171

Every entry in id order.

Returns ​

IterableIterator<readonly [string, T]>


get() ​

get(key): T | undefined

Defined in: packages/content/src/registry.ts:120

The value under a key, or undefined when the current build has none.

Parameters ​

key ​

string

Returns ​

T | undefined


has() ​

has(key): boolean

Defined in: packages/content/src/registry.ts:141

Whether the current build has an entry under the key.

Parameters ​

key ​

string

Returns ​

boolean


holder() ​

holder(key): Holder<T>

Defined in: packages/content/src/registry.ts:151

The holder for a key, created on first ask and reused afterwards, so two calls with the same key return the same object. Asking for a key the current build lacks returns an unbound holder that binds if a later build introduces the key.

Parameters ​

key ​

string

Returns ​

Holder<T>


idOf() ​

idOf(key): number | undefined

Defined in: packages/content/src/registry.ts:131

The id of a key in the current build, or undefined when it has no entry.

Parameters ​

key ​

string

Returns ​

number | undefined


keyOf() ​

keyOf(id): string | undefined

Defined in: packages/content/src/registry.ts:136

The key at an id, or undefined when the id is out of range.

Parameters ​

id ​

number

Returns ​

string | undefined


keys() ​

keys(): readonly string[]

Defined in: packages/content/src/registry.ts:161

Every key in id order. The array is frozen.

Returns ​

readonly string[]


rebuild() ​

rebuild(entries): void

Defined in: packages/content/src/registry.ts:99

Replaces every entry. Entries take ids 0 to n-1 in the order the iterable yields them.

Parameters ​

entries ​

Iterable<readonly [string, T]>

Returns ​

void

Throws ​

When one key appears twice in the same build.


values() ​

values(): readonly T[]

Defined in: packages/content/src/registry.ts:166

Every value in id order. The array is frozen.

Returns ​

readonly T[]