Skip to content
Shapemetry

@huukhanhnguyen/model / Store

Store

Store

Per-session asset registry. Every consumer builds its own instance — new Store() — there is no shared singleton.

Responsibilities (JSON-level only, never instantiates a Model):

  1. Store raw model JSONs by ID (host-facing lookup, e.g. catalog opens).
  2. Scan a document's parameters lane (root AND each components[] entry's own parameters, 2026-07-22 — a component may carry its OWN attached files, share.ts's law) for url-method parameters (an attached file IS such a parameter — type inferred from the url via assetTypeOf: font/image) plus the textures[] lane's image ops → pre-load by URL. Both maps are keyed by URL.

Typical session flow: const assets = new Store() assets.registerFromModel(json) // scan parameters/textures lanes await assets.loadFonts() // ASYNC phase (+ loadImages) const model = await Model.fromJSON(json, { store: assets })

Extends

Constructors

Constructor

new Store(): Store

Returns

Store

Inherited from

Notifier.constructor

failures

readonly failures: AssetFailure[] = []

Async pre-load failures (see AssetFailure) — one entry per url, replaced on retry, dropped on a later success. Emits "failures".

fonts

readonly fonts: Map<string, FontData>

Parsed fonts, keyed by URL (a font arg receives a url-method parameter's URL string — the url IS the key).

images

readonly images: Map<string, TextureData>

Decoded bitmaps for the texture lane's image source, by url.

models

readonly models: Map<string, unknown>

Methods

_dispose()

_dispose(): void

Returns

void

Inherited from

Notifier._dispose

addListener()

addListener(event, listener): () => void

Parameters

event

string

listener

Listener

Returns

() => void

Inherited from

Notifier.addListener

getFont()

getFont(key): FontData | null

Parameters

key

string

Returns

FontData | null

getImage()

getImage(url): TextureData | null

Parameters

url

string

Returns

TextureData | null

getModel()

getModel(id): unknown

Parameters

id

string

Returns

unknown

loadFonts()

loadFonts(): Promise<void>

Returns

Promise<void>

loadImages()

loadImages(): Promise<void>

Returns

Promise<void>

notify()

notify(event, ...args): void

Parameters

event

string

args

...unknown[]

Returns

void

Inherited from

Notifier.notify

queueImage()

queueImage(url): void

Queue an image url for the next loadImages() pass.

Parameters

url

string

Returns

void

registerFont()

registerFont(name, src): void

Parameters

name

string

src

string

Returns

void

registerFromModel()

registerFromModel(json): void

Parameters

json

unknown

Returns

void

registerImage()

registerImage(url, pixels): void

Seed decoded pixels directly (tests, platform bridges, editor uploads). Notifies "asset" so a Model already wired to this Store re-evaluates consumers (same path as a late async loadImages finish).

Parameters

url

string

pixels

TextureData

Returns

void

removeListener()

removeListener(event, listener): void

Parameters

event

string

listener

Listener

Returns

void

Inherited from

Notifier.removeListener

reset()

reset(): void

Returns

void

📖 3 min readEdit on GitHub