From 3ed8b48c19ec126b525d2fbe9d09863cf7b6098a Mon Sep 17 00:00:00 2001 From: Christian Baroni <7061887+christianbaroni@users.noreply.github.com> Date: Thu, 9 Jan 2025 20:55:45 +0000 Subject: [PATCH] [createRainbowStore] Adjust default `persistThrottleMs` --- src/state/internal/createRainbowStore.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/state/internal/createRainbowStore.ts b/src/state/internal/createRainbowStore.ts index 99be06daa24..e2751164f65 100644 --- a/src/state/internal/createRainbowStore.ts +++ b/src/state/internal/createRainbowStore.ts @@ -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' }); /** @@ -40,7 +39,7 @@ export interface RainbowPersistConfig> { serializer?: (state: StorageValue['state'], version: StorageValue['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; /** @@ -107,6 +106,8 @@ interface LazyPersistParams> { value: StorageValue | StorageValue; } +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. @@ -117,7 +118,7 @@ function createPersistStorage>(config: Rain const { deserializer = serializedState => defaultDeserializeState(serializedState, enableMapSetHandling), serializer = (state, version) => defaultSerializeState(state, version, enableMapSetHandling), - persistThrottleMs = PERSIST_RATE_LIMIT_MS, + persistThrottleMs = DEFAULT_PERSIST_THROTTLE_MS, storageKey, version = 0, } = config;