A lightweight, reactive state management class for JavaScript applications
  • JavaScript 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-09-09 15:13:02 +02:00
GameState.d.ts add d.ts 2026-09-09 15:13:02 +02:00
GameState.js add gamestats.js 2026-09-09 14:36:01 +02:00
LICENSE Initial commit 2026-09-09 14:35:33 +02:00
README.md Actualiser README.md 2026-09-09 14:55:13 +02:00

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>