Spaces:
Paused
Paused
Download src/web/js/gameState.js from deepondas/laya-snake: direct link, hf CLI and curl.
- Browser
- Download file 536 Bytes
-
https://huggingface.co/spaces/deepondas/laya-snake/resolve/main/src/web/js/gameState.js
- Command line
-
hf download hf://spaces/deepondas/laya-snake/src/web/js/gameState.js
-
curl -L -o gameState.js https://huggingface.co/spaces/deepondas/laya-snake/resolve/main/src/web/js/gameState.js
536 Bytes
| const listeners = new Set(); | |
| // The latest server snapshot (unchanged payload) and the one before it. | |
| export const game = { state: null, previous: null }; | |
| // Stores a fresh server snapshot and notifies every subscriber. | |
| export function applyState(s) { | |
| game.previous = game.state; | |
| game.state = s; | |
| for (const fn of listeners) fn(s, game.previous); | |
| } | |
| // Registers a callback run after every state change; returns an unsubscribe function. | |
| export function subscribe(fn) { | |
| listeners.add(fn); | |
| return () => listeners.delete(fn); | |
| } | |