mirror of
https://codeberg.org/HvK_Okla/Gamestats.js.git
synced 2026-09-16 23:21:22 +00:00
A lightweight, reactive state management class for JavaScript applications
- JavaScript 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| GameState.d.ts | ||
| GameState.js | ||
| LICENSE | ||
| README.md | ||
GameState.js
A lightweight, zero-dependency reactive state manager for JS game development.
GameState.js is a self-contained, pure JavaScript state management library built specifically for HTML5 games. It features path-based subscriptions, undo/redo time-traveling, batch updates, computed properties, transactions with auto-rollback, and persistence out of the box.
Designed to be simple, ethical, and fully autonomous—no package managers, build tools, or third-party CDNs required.
Features:
- Zero Dependencies: Pure Vanilla JavaScript (ES Modules / ES6+).
- Privacy & Autonomy: No npm, no external scripts, no tracking.
- Dot Notation Access: Access and mutate nested state easily (
player.position.x). - Granular Subscriptions: Subscribe to specific paths or global state changes.
- Time Travel (Undo / Redo): Built-in history management for puzzle games, turn-based systems, or editor steps.
- Computed Properties: Reactive values calculated automatically from state data.
- Batching & Transactions: Group multiple state changes into a single notification or run atomic operations with automatic rollback on error.
- Built-in LocalStorage Persistence: Save and load game progression with one method call.
- Middleware Support: Intercept, validate, or mutate state updates on the fly.
Quick Start
1. Download & Include
Simply download GameState.js from the Releases page, drop it into your project folder, and import it directly into your web page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Web Game</title>
</head>
<body>
<script type="module">
import GameState from './GameState.js';
// Initialize State
const game = new GameState({
player: { name: 'Alex', hp: 100 },
score: 0
});
// Subscribe to changes
game.subscribe('player.hp', (hp) => {
console.log(`Player HP updated: ${hp}`);
});
// Update state
game.set('player.hp', 85);
</script>
</body>
</html>