Skip to content

refactor(store): simplify state management + computeds#321

Merged
mihar-22 merged 4 commits intomainfrom
refactor/store-state-simplification
Jan 22, 2026
Merged

refactor(store): simplify state management + computeds#321
mihar-22 merged 4 commits intomainfrom
refactor/store-state-simplification

Conversation

@mihar-22
Copy link
Copy Markdown
Member

@mihar-22 mihar-22 commented Jan 22, 2026

Summary

Simplified state management API - easier to reason about with explicit access patterns. Total size is 560B.

import { createState, createComputed, flush, isState } from '@videojs/store';

State API

// Access via .current (frozen on update)
const { volume, muted } = store.state.current;

// Subscribe to changes  
state.subscribe(() => { ... });
state.subscribe(['volume'], () => { ... });

// Mutate via explicit methods
state.set('volume', 0.5);
state.patch({ volume: 0.5, muted: true });

Computed (new)

const effectiveVolume = createComputed(
  store.state,
  ['volume', 'muted'],
  ({ volume, muted }) => muted ? 0 : volume
);

effectiveVolume.current;      // derived value
effectiveVolume.subscribe();  // notified on change
effectiveVolume.destroy();    // cleanup

Simplified React/Lit integrations

// React - was 15 lines, now 3
export function useSnapshot<T extends object>(state: State<T>): T {
  return useSyncExternalStore(state.subscribe, () => state.current, () => state.current);
}

@vercel
Copy link
Copy Markdown

vercel bot commented Jan 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
vjs-10-website Skipped Skipped Jan 22, 2026 10:55am

Request Review

@mihar-22 mihar-22 changed the title refactor(store): simplify state management and add computed support refactor(store): simplify state management + computeds Jan 22, 2026
@mihar-22 mihar-22 added this to the Alpha milestone Jan 22, 2026
@mihar-22 mihar-22 added the store label Jan 22, 2026
@mihar-22 mihar-22 self-assigned this Jan 22, 2026
@mihar-22 mihar-22 moved this to Done in Video.js 10 Roadmap Jan 22, 2026
@mihar-22 mihar-22 merged commit e01ce5b into main Jan 22, 2026
4 checks passed
@mihar-22 mihar-22 deleted the refactor/store-state-simplification branch January 22, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant