Skip to content

Commit

Permalink
style: replace pluginOptions with globalOptions for consistency with …
Browse files Browse the repository at this point in the history
…docs

- Removed `pluginOptions` and directly used `globalOptions` for improved clarity
- Aligned variable naming with documentation to ensure consistency
- Simplified code by eliminating redundant variable assignments
  • Loading branch information
stephenjason89 committed Jan 15, 2025
1 parent 918920d commit aa94463
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import type { GlobalPersistOptions, Storage } from './types.js'
import { applyStateFilter, createLogger, getObjectDiff, isPromise, queueTask } from './utils.js'

export function createStatePersistence<S extends StateTree = StateTree>(
globalOptions?: GlobalPersistOptions<S>,
globalOptions: GlobalPersistOptions<S> = {},
): PiniaPlugin {
const pluginOptions = globalOptions || {}
const queues: Record<string, Promise<void>> = {}
const log = createLogger(pluginOptions.debug)
const log = createLogger(globalOptions.debug)

const detectStorage = (): null | Storage => {
if (typeof window === 'undefined') {
Expand Down Expand Up @@ -42,7 +41,7 @@ export function createStatePersistence<S extends StateTree = StateTree>(
clientOnly = false,
include = null,
exclude = null,
} = { ...{ ...pluginOptions, key: undefined }, ...(typeof storeOptions === 'object' && storeOptions) }
} = { ...{ ...globalOptions, key: undefined }, ...(typeof storeOptions === 'object' && storeOptions) }

if (!storage || ((clientOnly || storage.constructor.name.includes('LocalForage')) && typeof window === 'undefined')) {
log.warn(`Skipping persistence for ${context.store.$id}: Storage unavailable or client-only restriction applied.`)
Expand All @@ -51,7 +50,7 @@ export function createStatePersistence<S extends StateTree = StateTree>(

// Combine global prefix with store-specific key
const getPrefixedKey = (storeKey: string) =>
pluginOptions.key ? `${pluginOptions.key}:${storeKey}` : storeKey
globalOptions.key ? `${globalOptions.key}:${storeKey}` : storeKey

let isRestoringState: boolean
const loadState = () => {
Expand Down

0 comments on commit aa94463

Please sign in to comment.