A ClojureScript library for creating atoms backed by HTML5 web storage with automatic persistence and cross-window synchronization.
storage-atom is a ClojureScript library that creates atoms backed by HTML5 web storage (localStorage and sessionStorage). It automatically persists atom state to browser storage and synchronizes changes across multiple tabs or windows, solving the problem of maintaining consistent application state across browser sessions.
ClojureScript developers building web applications that require persistent client-side state or real-time state synchronization across browser tabs.
Developers choose storage-atom because it provides a simple, idiomatic ClojureScript interface to web storage with automatic persistence and cross-window synchronization, eliminating the need to manually manage storage operations while maintaining the familiar atom API.
ClojureScript atoms backed by HTML5 web storage.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Any change to the atom is automatically saved to localStorage or sessionStorage, ensuring state survives page reloads without manual intervention, as shown in the example where swap! updates storage.
Modifications in one browser tab or window are automatically propagated to all others, enabling real-time state sharing, which is core to the library's value proposition.
Includes a default 10ms debounce delay to batch rapid writes, preventing excessive storage operations, and can be adjusted via storage-delay or dynamic vars for performance tuning.
Provides helper functions like remove-local-storage! and clear-local-storage! that properly update associated atoms, avoiding inconsistencies when clearing storage manually.
The README admits this approach is much slower than direct web storage access because the entire atom contents are written on every swap!, making it inefficient for large or frequently updated atoms.
Cross-window propagation doesn't always work in browsers like Chrome when accessing files directly without a web server, limiting reliability in local development or certain deployment scenarios.
Inherits constraints of HTML5 web storage, such as string-based serialization and typical size limits (5-10MB), requiring careful data management; Transit support helps but is optional.