Skip to content

Tweak Snapshot type so it treats regular arrays and maps the same as ArraySchema and MapSchema - #9

Open
FTWinston wants to merge 3 commits into
mainfrom
snapshot-type
Open

Tweak Snapshot type so it treats regular arrays and maps the same as ArraySchema and MapSchema#9
FTWinston wants to merge 3 commits into
mainfrom
snapshot-type

Conversation

@FTWinston

@FTWinston FTWinston commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

I stupidly thought I was working on a fork, and pushed this to main. I've reverted it now. Sorry!

This PR allows the Snapshot type to treat Map types the same way it treats MapSchema types. It makes it easier to write prop types for react components without having to reference colyseus schema types directly.

In a shared package, I have:

interface IPlayerState {
    weapons: IMap<string, IWeaponState>;
}

In my engine package, I have:

class PlayerState extends Schema implements IPlayerState {
    @type({ map: WeaponState }) weapons = new MapSchema<WeaponState>();
}

And in my frontend package, I have:

const InventoryDisplay(props: { player: Snapshot<IPlayerState> }) {
    ...
}

This pattern already works for ArraySchema and classes extending Schema, but the transformation of MapSchema<T> to Record<string, T> means this change is needed to work with MapSchema.

@FTWinston
FTWinston marked this pull request as ready for review June 1, 2026 23:09
endel added a commit that referenced this pull request Aug 11, 2026
The IArray/IMap types and structural Snapshot branches were already
absorbed into this branch (49bb64a) in extended form — concrete
ArraySchema/MapSchema branches kept first for element inference, v5
internals stripped — so conflicts resolve to the branch's version.
New from the PR: prepublishOnly → prepare, so git revisions
(npm i colyseus/react-tools#0.18) build dist on install.

Assisted-by: Claude Fable 5
endel added a commit that referenced this pull request Aug 11, 2026
Assisted-by: Claude Fable 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant