Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NgRx/signals]add:withStorageSync new function #7

Open
mzkmnk opened this issue Jan 1, 2025 · 0 comments
Open

[NgRx/signals]add:withStorageSync new function #7

mzkmnk opened this issue Jan 1, 2025 · 0 comments
Assignees

Comments

@mzkmnk
Copy link
Member

mzkmnk commented Jan 1, 2025

Value Encoding/Decoding Support (Encryption, Compression)

Description
Currently, the library supports basic JSON serialization/deserialization when writing to or reading from storage. It would be beneficial to introduce a mechanism for optional encoding or decoding of data. For example, users may want to encrypt or compress data before storing it to protect sensitive information or reduce space usage.

Why This Matters

  • Security: Storing data in plain JSON can expose sensitive information if someone gains access to localStorage/sessionStorage.
  • Efficiency: Compressing large payloads can help reduce storage size limits.

Possible Approaches

  • Allow developers to provide custom encode and decode functions in the configuration.
  • Keep JSON serialization as the default but enable optional plug-in mechanisms for encryption or compression libraries.
  • Document best practices for key management, given that encryption on the client side has inherent limitations.

Version Management and Migrations

Description
As applications evolve, the shape of the state can change. Introducing a version management system would allow seamless migrations of stored data. For instance, when the state structure changes, the library could detect a version mismatch, run a custom migration function, and update the stored data accordingly.

Why This Matters

  • Backward Compatibility: Users with old stored data can have it automatically upgraded to the new format.
  • Reduced Risk: Prevents errors that might occur when trying to read outdated keys or data structures.

Possible Approaches

  • Add a version field to the library’s configuration, which is stored alongside the data.
  • If a version mismatch is detected, trigger a user-defined migration function.
  • After a successful migration, re-save data under the new version, and optionally clean up old keys.

Integration with or Fallback to IndexedDB

Description
For larger or more complex data storage needs, localStorage or sessionStorage might be insufficient. IndexedDB can handle bigger data payloads and more advanced use cases (like indexing, complex queries, or binary data). Adding optional support for IndexedDB would help accommodate apps that need more robust storage capabilities.

Why This Matters

  • Capacity: IndexedDB typically allows storing more data than localStorage.
  • Performance & Flexibility: IndexedDB can store structured objects, handle indexing, and support partial updates more effectively.

Possible Approaches

  • Abstract the storage layer so users can supply an IndexedDB-based service that implements a similar interface to Storage.
  • Provide a fallback mechanism: if storing data in localStorage fails (e.g., quota errors), automatically switch to IndexedDB.
  • Offer async operations for reading and writing, possibly wrapped in Signals or Observables for consistency with the rest of the library.
@mzkmnk mzkmnk self-assigned this Jan 1, 2025
@mzkmnk mzkmnk changed the title add:withStorageSync new function :withStorageSync new function Jan 1, 2025
@mzkmnk mzkmnk changed the title :withStorageSync new function [Ngrx/signals]add:withStorageSync new function Jan 1, 2025
@mzkmnk mzkmnk changed the title [Ngrx/signals]add:withStorageSync new function [NgRx/signals]add:withStorageSync new function Jan 1, 2025
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

No branches or pull requests

1 participant