Skip to content

Commit

Permalink
[createRainbowStore] Adjust default persistThrottleMs
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbaroni committed Jan 10, 2025
1 parent bd63de7 commit 958cd90
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/state/internal/createRainbowStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { debounce } from 'lodash';
import { MMKV } from 'react-native-mmkv';
import { StateCreator, create } from 'zustand';
import { PersistOptions, PersistStorage, StorageValue, persist, subscribeWithSelector } from 'zustand/middleware';
import { IS_IOS } from '@/env';
import { RainbowError, logger } from '@/logger';

const PERSIST_RATE_LIMIT_MS = 3000;

const rainbowStorage = new MMKV({ id: 'rainbow-storage' });

/**
Expand Down Expand Up @@ -40,7 +39,7 @@ export interface RainbowPersistConfig<S, PersistedState = Partial<S>> {
serializer?: (state: StorageValue<PersistedState>['state'], version: StorageValue<PersistedState>['version']) => string;
/**
* The throttle rate for the persist operation in milliseconds.
* @default time.seconds(3)
* @default iOS: time.seconds(3) | Android: time.seconds(5)
*/
persistThrottleMs?: number;
/**
Expand Down Expand Up @@ -107,6 +106,8 @@ interface LazyPersistParams<S, PersistedState extends Partial<S>> {
value: StorageValue<S> | StorageValue<PersistedState>;
}

const DEFAULT_PERSIST_THROTTLE_MS = IS_IOS ? 3000 : 5000;

/**
* Creates a persist storage object for the Rainbow store.
* @param config - The configuration options for the persistable Rainbow store.
Expand All @@ -117,7 +118,7 @@ function createPersistStorage<S, PersistedState extends Partial<S>>(config: Rain
const {
deserializer = serializedState => defaultDeserializeState<PersistedState>(serializedState, enableMapSetHandling),
serializer = (state, version) => defaultSerializeState<PersistedState>(state, version, enableMapSetHandling),
persistThrottleMs = PERSIST_RATE_LIMIT_MS,
persistThrottleMs = DEFAULT_PERSIST_THROTTLE_MS,
storageKey,
version = 0,
} = config;
Expand Down

0 comments on commit 958cd90

Please sign in to comment.