Skip to content

Commit

Permalink
feat: set default quals function for store/cache
Browse files Browse the repository at this point in the history
  • Loading branch information
schummar committed Mar 7, 2024
1 parent af7dea6 commit 9445310
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/core/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PromiseWithState } from '@lib/promiseWithState';
import type { Duration, Selector } from './commonTypes';
import { allResources, type ResourceGroup } from './resourceGroup';
import { Store, createStore, type Calculate, type StoreOptions } from './store';
import { deepEqual } from '@lib/equals';

export interface CacheGetOptions {
update?: 'whenMissing' | 'whenStale' | 'force';
Expand Down Expand Up @@ -353,5 +354,6 @@ export const createCache = /* @__PURE__ */ Object.assign(create, {
invalidateOnActivation: true,
clearUnusedAfter: { days: 1 },
retain: { milliseconds: 1 },
equals: deepEqual,
} as CacheOptions<unknown>,
});
5 changes: 4 additions & 1 deletion src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type BoundStoreMethods<T, Methods extends StoreMethods> = Methods &

export interface StoreOptions {
retain?: Duration;
equals?: SubscribeOptions['equals'];
}

export interface StoreOptionsWithMethods<T, Methods extends StoreMethods> extends StoreOptions {
Expand Down Expand Up @@ -444,5 +445,7 @@ function create<T, Methods extends StoreMethods>(
}

export const createStore = /* @__PURE__ */ Object.assign(create, {
defaultOptions: {} as StoreOptions,
defaultOptions: {
equals: deepEqual,
} as StoreOptions,
});
2 changes: 1 addition & 1 deletion src/react/useStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function useStore<T, S>(store: Store<T>, argument1?: any, argument2?: any
);
const {
disableTrackingProxy = true,
equals = deepEqual,
equals = store.options.equals ?? deepEqual,
withViewTransition,
...options
} = (typeof argument1 === 'object' ? argument1 : argument2 ?? {}) as UseStoreOptions<S>;
Expand Down

0 comments on commit 9445310

Please sign in to comment.