donniewest / unissist Goto Github PK
View Code? Open in Web Editor NEW⛑ A ~300b unistore helper to persist your data using equally tiny storage adapters
⛑ A ~300b unistore helper to persist your data using equally tiny storage adapters
im new to this. what's the best way to just select objects i want to persist?
Unissist already allows to modify the state when saving it through the map
option.
In some cases it's usefull to also be able to modify the state while loading it.
Allowing the migration function to return a promise would allow for different use cases.
For example to only import()
(or otherwise load code) for migrations from the stores version.
This is usefull when you had lots of breaking changes in the store layout, but don't wan't to ship all migration code in the inital bundle.
To allow for showing user message the store could implement a migrating
flag which is by default false
.
To not further delay the store hydration, a check if the returned value is a promise could be made instead of always delaying the execution by a tick.
Edit: if you like the idea I could provide a PR within the next few days.
Is there any way to exclude some states from the cache?
First of all - freaking awesome library.
// store state now includes a
hydrated
that tells you whether or not the state has been rehydrated from the store
Could you please elaborate what hydrated does and perhaps add a few lines of example code
Currently I have a separate store file that looks like this:
import createStore from 'unistore';
import persistStore from 'unissist';
import indexedDBAdapter from 'unissist/integrations/indexdbAdapter';
const initialState = {
//data
};
const store = createStore(initialState);
const adapter = indexedDBAdapter();
const config = {
debounceTime: 100,
map: state => (
{
//data
}
)
};
persistStore(store, adapter, config);
store.subscribe((state) => console.log(state));
export default store;
If I use persistStore(store, adapter)
then it will refresh correctly, however using the map, it maps the new store it creates to the adapter then hydrates store. Should this be structured a different way? I am not sure why having the config map out state causes it to default to initial state instead of hydrating. Is there something here that would cause the map to run before it rehydrates?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.