mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
add indexeddb storage for zustand
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { del, get, set } from 'idb-keyval';
|
||||
import mergeWith from 'lodash/mergeWith';
|
||||
|
||||
import { StateStorage } from 'zustand/middleware';
|
||||
/**
|
||||
* A custom deep merger that will replace all 'columns' items with the persistent
|
||||
* state, instead of the default merge behavior. This is important to preserve the user's
|
||||
@@ -17,3 +18,18 @@ export const mergeOverridingColumns = <T>(persistedState: unknown, currentState:
|
||||
return undefined;
|
||||
});
|
||||
};
|
||||
|
||||
export const idbStateStorage: StateStorage = {
|
||||
getItem: async (name: string): Promise<null | string> => {
|
||||
console.log(name, 'has been retrieved');
|
||||
return (await get(name)) || null;
|
||||
},
|
||||
removeItem: async (name: string): Promise<void> => {
|
||||
console.log(name, 'has been deleted');
|
||||
await del(name);
|
||||
},
|
||||
setItem: async (name: string, value: string): Promise<void> => {
|
||||
console.log(name, 'with value', value, 'has been saved');
|
||||
await set(name, value);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user