state-facade-patterns Svelte Themes

State Facade Patterns

Creates a reactive state object with Svelte 5 runes that acts like a plain object while maintaining reactivity through getters/setters and providing utility methods.

Service Class

Even safer solution, with read/write access and generated accessors! My example is for managing the front-end state of a Tauri app.

Usage Example

import { MyService } from './path/to/your/service';

// Access current state
const currentState = MyService.current;

// Update state
MyService.someProperty = newValue;

// Get snapshot
const stateSnapshot = MyService.snapshot;

Features

  • Dynamic Accessors: Automatically generated getters and setters for state properties.
  • Type Safety: Ensures correct types for read/write operations.

License

MIT


Top categories

Loading Svelte Themes