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

Custom Persistence (per Unit persistence) - Idea/Proposal/Question? #1

Closed
IgnusG opened this issue Nov 17, 2020 · 1 comment
Closed

Comments

@IgnusG
Copy link

IgnusG commented Nov 17, 2020

So I just wanted to ask if Activejs could/would support:

  1. Custom Persistent Storage
    Something along the lines of providing an interface (get, set, observe...) which then a developer can provide and handle things like serialization, maybe even initial values etc. themselves. More specifically for example an IndexedDB wrapper might be interesting - here serialization for example would not have to (and should not) be done.

  2. Storage Specification per Unit Type
    Following the first point, it would be nice to specify this storage interface per unit (not sure if that's already/or even possible - since it needs to be set during configuration of Activejs I assume it isn't). This way one could for example save an "image blob list" unit in the more performant (and serialization-free) IndexedDB and some other smaller units (for example list of updogs) in eg. a synchronizable (and serialized) extension storage (browser.storage.sync this is specific to browser extensions).

Both of these could be done by not using Activejs' persistence, and instead listening on the object changes and saving them ourselves.

Would this observer approach instead be the recommended way to go?
Or would/should the above 2 ideas (or one of them) be in the scope of Activejs?

What do you think?

Generally asking anyone (inside and outside the Activejs team) who's interested

@dabalyan
Copy link
Member

hey @IgnusG thanks for dropping by :)

1. Yes, you can change the default storage for persistent Units. You can change it to any storage interface (even custom implementation) that implements the Storage interface. You can find more information in the docs, here. However you can't handle the serialization outside of ActiveJS, as it's done internally. Regarding an IndexedDB wrapper, actually a very early implementation used the IndexedDB but it was hard to mix synchronous code with asynchronous IndexedDB, only way around that was to load all the stored state from the IndexedDB synchronously while blocking the whole application, because the persisted value is supposed to override the initialValue of the Unit. So IndexedDB was dropped in favor of localStorage and sessionStorage. You can still write a wrapper and provide it to ActiveJS, but it's probably not worth it.

2. As mentioned in the above point, asynchronous persistent storage is not feasible at the moment, as the Units are supposed to load the values synchronously. But thanks for mentioning it, because you can change the storage for specific Unit, I updated the docs, you can see it here.

In general, I'd advise to stick with synchronous storage.
Also, ActiveJS doesn't recommend storing non-serializable values in it, it might still work but there are no guarantees.

Hope that answers your questions.

@IgnusG IgnusG closed this as completed Dec 17, 2021
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

2 participants