Skip to content

Commit

Permalink
refactor(with-indexeddb): rename methods
Browse files Browse the repository at this point in the history
  • Loading branch information
MizukiSugiyama committed Jan 22, 2025
1 parent af02b32 commit 2876625
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions libs/ngrx-toolkit/src/lib/storageSync/with-indexeddb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ const PROMISE_NOOP = () => Promise.resolve();

export type WithIndexedDBSyncFeatureResult = EmptyFeatureResult & {
methods: {
readFromIndexedDB(): Promise<void>;
readFromStorage(): Promise<void>;

writeToIndexedDB(): Promise<void>;
writeToStorage(): Promise<void>;

clearIndexedDB(): Promise<void>;
clearStorage(): Promise<void>;
};
};

const withIndexedDBSyncFeatureStub: Pick<
WithIndexedDBSyncFeatureResult,
'methods'
>['methods'] = {
readFromIndexedDB: PROMISE_NOOP,
writeToIndexedDB: PROMISE_NOOP,
clearIndexedDB: PROMISE_NOOP,
readFromStorage: PROMISE_NOOP,
writeToStorage: PROMISE_NOOP,
clearStorage: PROMISE_NOOP,
};

export type WithIndexedDBFn<State extends object> = (
Expand Down Expand Up @@ -96,7 +96,7 @@ export function withIndexedDB<State extends object>(): WithIndexedDBFn<State> {
}

return {
async readFromIndexedDB(): Promise<void> {
async readFromStorage(): Promise<void> {
const dbState = (await indexedDBService.read(
dbName,
storeName
Expand All @@ -115,13 +115,13 @@ export function withIndexedDB<State extends object>(): WithIndexedDBFn<State> {
patchState(store, dbState.value);
},

async writeToIndexedDB(): Promise<void> {
async writeToStorage(): Promise<void> {
const state = select(getState(store) as State);

await indexedDBService.write(dbName, storeName, state);
},

async clearIndexedDB(): Promise<void> {
async clearStorage(): Promise<void> {
await indexedDBService.clear(dbName, storeName);
},
};
Expand All @@ -142,12 +142,12 @@ export function withIndexedDB<State extends object>(): WithIndexedDBFn<State> {

if (autoSync) return;

store.readFromIndexedDB().then((_) => {
store.readFromStorage().then((_) => {
runInInjectionContext(envInjector, () => {
effect(() =>
((_state) => {
Promise.resolve().then(async () => {
await store.writeToIndexedDB();
await store.writeToStorage();
});
})(getState(store))
);
Expand Down

0 comments on commit 2876625

Please sign in to comment.