Skip to content

Instantly share code, notes, and snippets.

View viridia's full-sized avatar

Talin viridia

View GitHub Profile
@viridia
viridia / SaveGame.ts
Created January 31, 2023 19:17
Example of Structural Sharing for saved games.
export class SavedGameStore<T extends object> {
private prev: { [key: string]: string } = {};
private next: { [key: string]: string } = {};
constructor(private options: ISaveGameOptions = {}) {}
/** Return a list of saved games. */
public list(): ISavedGameRoot[] {
/** Get all the local storage keys that begin with the word 'save'. */
return Object.keys(localStorage)