-
Notifications
You must be signed in to change notification settings - Fork 0
Immutable state, only reassigning changed subtree #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
a5764f3
Add immutable useRoomState hook
FTWinston ab4d115
Extend schema, add components for displaying render count of each part
FTWinston 79b07d6
Disable strict mode so render count doesn't go up by two with every c…
FTWinston f07f26f
Memoised components so they don't rerender if their props don't change
FTWinston 455d2a8
Highlighting the most recent rendered components, instead of displayi…
FTWinston a573471
Tidy appearance, add inventory actions
FTWinston 0d3f778
Add an initial test
FTWinston 829f36e
Highlight items when they are created, as well as when modifying
FTWinston d0c7a4a
Add some more tests
FTWinston c3e53c3
Add additional tests, including skipped array tests that currently fa…
FTWinston aa19d76
Adjust array handling to resolve failing test
FTWinston 8a2066d
Update to latest @colyseus/schema
FTWinston 17a6fe2
Rework hook to intercept decoder changes, instead of adding listeners…
FTWinston bfe780d
Add colyseus.js dependency so useRoomState can be uncommented
FTWinston 9957238
Fix some imports, remove getReactCallbacks
FTWinston e86dbed
Update src/schema/createSnapshot.ts
FTWinston c37e790
Re-enable strict mode
FTWinston ffc9ba1
Ensure inventory won't get two items of the same type
FTWinston 9facdea
move visual tests to 'example' folder. setup package structure for pu…
endel a634c24
Remove duplicate hook and App files
FTWinston 8709ecb
Track items' parents, and only iterate dirty subtrees when creating a…
FTWinston 664decd
Initial plan
Copilot 623da1e
Add GitHub Actions CI workflow for build and test
Copilot 338f79a
Add permissions block to CI workflow for security
Copilot 487ac6b
Add GitHub Actions CI workflow for build and test
FTWinston 3e54984
Initial plan
Copilot fe56fd9
Add comprehensive array schema tests and update CI workflow
Copilot 0a8e74e
Add test for modifying last task in array
Copilot 302515c
Merge pull request #5 from colyseus/copilot/sub-pr-3
FTWinston 5cb729d
Update to @colyseus/schema 4 and @colyseus/sdk 0.17
FTWinston 7cc4777
Fix CI build error
FTWinston 4521afc
publish 0.1.0 for testing
endel f94a387
Add (failing) tests that every change isn't creating new subscription…
FTWinston 1d9148d
Ensure stable callbacks are passed to useSyncExternalStore, so that e…
FTWinston 48e80aa
Move example to examples/visualisation
FTWinston 0fa1f1e
Added demo-client and demo-server projects that reproduce the error t…
FTWinston 65318b2
Remove a fallback in createSnapshot that isn't needed as of @colyseus…
FTWinston 9a96779
myString doesn't update on every state change
FTWinston 7d0bb90
Add missing function
FTWinston 6fb907a
More permissive peer dependencies
FTWinston 9db94bb
Add dedupe rule to demo-client vite config, to resolve error
FTWinston 3b41ce8
Update @colyseus/sdk to resolve seat reservation error when schema is…
FTWinston 47c6d84
useRoomState no longer interferes with with Callbacks.get or any othe…
FTWinston fc1e953
avoid using 'instanceof' due to duplicated @colyseus/schema package i…
endel 4b2b2a2
fix 'dirty' cleanup
endel fe3e457
useRoomState and useColyseusState now handle falsy parameters
FTWinston 889ca66
bump version
endel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| .item { | ||
| border: 1px solid #ccc; | ||
| padding: 0.5em 1em; | ||
| background-color: #242424; | ||
| corner-shape: squircle; | ||
| border-radius: 1em; | ||
| } | ||
|
|
||
| .item-type { | ||
| font-weight: bold; | ||
| } | ||
|
|
||
| .item-quantity { | ||
| font-style: italic; | ||
| text-align: center; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { memo } from 'react'; | ||
| import { Item } from '../schema/MyRoomState'; | ||
| import { Snapshot } from '../schema/createSnapshot'; | ||
| import { useRenderHighlight } from './useRenderHighlight'; | ||
| import './ItemDisplay.css' | ||
|
|
||
| type Props = { | ||
| item: Snapshot<Item>; // You'd normally pass in the fields rather than the item class itself, but doing it this way lets the component only re-render when the item changes. | ||
| } | ||
|
|
||
| export const ItemDisplay = memo(({ item }: Props) => { | ||
| const highlightRef = useRenderHighlight<HTMLDivElement>(); | ||
|
|
||
| return ( | ||
| <div className="item" ref={highlightRef}> | ||
| <div className="item-type">{item.type}</div> | ||
| <div className="item-quantity">x{item.quantity}</div> | ||
| </div> | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| .items { | ||
| border: 1px solid #ccc; | ||
| padding: 1em; | ||
| min-height: 3em; | ||
| display: flex; | ||
| gap: 1em; | ||
| background-color: #242424; | ||
| corner-shape: squircle; | ||
| border-radius: 1em; | ||
| box-sizing: border-box; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { memo } from 'react'; | ||
| import { ArraySchema } from '@colyseus/schema'; | ||
| import { Snapshot } from '../schema/createSnapshot'; | ||
| import { Item } from '../schema/MyRoomState'; | ||
| import { ItemDisplay } from './ItemDisplay'; | ||
| import { useRenderHighlight } from './useRenderHighlight'; | ||
| import './ItemsDisplay.css' | ||
|
|
||
| type Props = { | ||
| items: Snapshot<ArraySchema<Item>>; | ||
| } | ||
|
|
||
| export const ItemsDisplay = memo(({ items }: Props) => { | ||
| const highlightRef = useRenderHighlight<HTMLDivElement>(); | ||
|
|
||
| return ( | ||
| <div className="items" ref={highlightRef}> | ||
| {items.map(item => ( | ||
| <ItemDisplay key={item.type} item={item} /> | ||
| ))} | ||
| </div> | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| .player { | ||
| border: 1px solid #ccc; | ||
| padding: 1em; | ||
| margin: 1em; | ||
| background-color: #242424; | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 0.5em; | ||
| corner-shape: squircle; | ||
| border-radius: 1em; | ||
| } | ||
|
|
||
| .player-field { | ||
| display: flex; | ||
|
|
||
| & > :first-child { | ||
| min-width: 6em; | ||
| } | ||
|
|
||
| & > :last-child { | ||
| flex-grow: 1; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { memo } from 'react'; | ||
| import { Player } from '../schema/MyRoomState'; | ||
| import { Snapshot } from '../schema/createSnapshot'; | ||
| import { ItemsDisplay } from './ItemsDisplay'; | ||
| import { PositionDisplay } from './PositionDisplay'; | ||
| import { useRenderHighlight } from './useRenderHighlight'; | ||
| import './PlayerDisplay.css' | ||
|
|
||
| type Props = { | ||
| player: Snapshot<Player>; // You'd normally pass in the fields rather than the player class itself, but doing it this way lets the component only re-render when the item changes. | ||
| } | ||
|
|
||
| export const PlayerDisplay = memo(({ player }: Props) => { | ||
| const highlightRef = useRenderHighlight<HTMLDivElement>(); | ||
|
|
||
| return ( | ||
| <div className="player" ref={highlightRef}> | ||
| <div className="player-field"><strong>Name:</strong><div>{player.name}</div></div> | ||
| <div className="player-field"><strong>Position:</strong><PositionDisplay position={player.position} /></div> | ||
| <div className="player-field"><strong>Inventory:</strong><ItemsDisplay items={player.inventory} /></div> | ||
| </div> | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| .players { | ||
| border: 1px solid #ccc; | ||
| padding: 1em; | ||
| margin: 1em; | ||
| background-color: #242424; | ||
| corner-shape: squircle; | ||
| border-radius: 1em; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { MapSchema } from '@colyseus/schema'; | ||
| import { memo } from 'react'; | ||
| import { Player } from '../schema/MyRoomState'; | ||
| import { Snapshot } from '../schema/createSnapshot'; | ||
| import { useRenderHighlight } from './useRenderHighlight'; | ||
| import { PlayerDisplay } from './PlayerDisplay'; | ||
| import './PlayersDisplay.css' | ||
|
|
||
| type Props = { | ||
| players: Snapshot<MapSchema<Player>>; | ||
| } | ||
|
|
||
| export const PlayersDisplay = memo(({ players }: Props) => { | ||
| const highlightRef = useRenderHighlight<HTMLDivElement>(); | ||
|
|
||
| return ( | ||
| <div className="players" ref={highlightRef}> | ||
| <h2>Players</h2> | ||
|
|
||
| {Object.entries(players).map(([id, player]) => ( | ||
| player !== undefined && ( | ||
| <PlayerDisplay key={id} player={player} /> | ||
| ) | ||
| ))} | ||
| </div> | ||
| ); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.