You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ecs: allow Map and Set resources with a default, and symbol-keyed maps #247
Declaring a resource of type Map or Set is narrow: ReadonlyMap<symbol, unknown> and Resource.Key are rejected ("keyof isn't a declared type"), and a ReadonlySet takes no default.
Case (mecs, @adobe/ecs 0.2.4)
History keeps a note of the values it wrote when it applied an undo/redo, so the finalizer that records resource changes skips them. It is a set of strings ("<index>=<json>"), declared as ReadonlySet<string> with no default; we had wanted ReadonlyMap<Resource.Key, unknown> (key to value) and a default: new Set().
`keyof` isn't a declared type (for the Resource.Key / symbol key)
default isn't of its declared type (for the Set)
We worked around it by encoding keys and values in a string.
Requested
Allow Map/Set (readonly) with a default of the same type, and allow a symbol-typed map key, or document the limits of declared types and why.
Addressed in #250 (Adobe-Firefly/ecs#9), with one correction to the premise: a ReadonlySet or ReadonlyMap resource needs no default. It starts empty in each world. Giving it one now says "…which starts empty in each world: leave its default out".
A set or map of what isn't data now registers as a value that isn't data, still starting empty in each world. That covers a symbol, Resource.Key or Component.Key, a class, or unknown, so ReadonlyMap<Resource.Key, unknown> works. Symbol keys stay out of data: data crosses threads by structured clone, which refuses symbols, and is saved by schema. So such a map stays on the world's thread and isn't persisted, which suits the history's note.
Activity
krisnye commentedon Nov 1, 2026
Addressed in #250 (Adobe-Firefly/ecs#9), with one correction to the premise: a
ReadonlySetorReadonlyMapresource needs nodefault. It starts empty in each world. Giving it one now says "…which starts empty in each world: leave its default out".A set or map of what isn't data now registers as a value that isn't data, still starting empty in each world. That covers a symbol,
Resource.KeyorComponent.Key, a class, orunknown, soReadonlyMap<Resource.Key, unknown>works. Symbol keys stay out of data: data crosses threads by structured clone, which refuses symbols, and is saved by schema. So such a map stays on the world's thread and isn't persisted, which suits the history's note.