-
Notifications
You must be signed in to change notification settings - Fork 4
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
Whitelisted properties do not persist for newer valtio versions #7
Comments
Thanks for sharing and digging! I have a new model I want to submit to this repo soon it might fix this. I've been using the new version for sometime, and going to take it to production by the end of this month. I'll keep you updated on how the new version fairs. |
Sounds great, thanks for the quick response! |
Hey there, just wondering if there's been any progress on this since the last post? :) |
Hey @dawsonbooth - sorry about that, I haven't made it public yet. I can share the work for it though. It's a cool driver that can be used with anything on top. Valtio, redux or anything can connect to the underlying layer which handles reading/writing to disk. I called it
I then connected it to proxy like this:
I then use it like this:
|
Wow, this is awesome! I'll look into wiring this into what we have - thank you so much! |
Thanks! It's been working super well. The main blocker for me to get to public is how I did retries and error capturing, not sure if we should ship that by default, but it's been pretty cool, I used debounce as when changes were high, it was wasting resources by writing too much. I'm not sure the API for how to debounce makes sense:
|
A simple implementation if you don't want to handle migration, etc… on the web with local storage. function proxyWithLocalStorage<T extends object>(key: string, initialValue: T) {
if (typeof window === "undefined") return proxy(initialValue);
const storageItem = localStorage.getItem(key);
const state = proxy(storageItem !== null ? (JSON.parse(storageItem) as T) : initialValue);
subscribe(state, () => localStorage.setItem(key, JSON.stringify(state)));
return state;
} |
valtio-persist is not persisting "whitelisted" properties specified with
persistStrategies
as documented. When thepersistStrategies
is set holistically to eitherPersistStrategy.SingleFile
orPersistStrategy.MultiFile
, it properly persists the entirety of the proxy object.I tracked this down to the
persistPath
function which is simply not being called when a whitelisted property updates. I assume this is because the subscription fails.I suspect it has to do with this valtio change in v1.7.1.
For the time being, we've downgraded to the version listed in this repo's
package.json
, v1.2.5, but it would be nice to be able to use this library on newer versions.The text was updated successfully, but these errors were encountered: