Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface StoreSeparateConfig<O>

Configuration for storeSeparate

Type parameters

  • O: Record<string, any>

Hierarchy

  • CommonConfig
    • StoreSeparateConfig

Index

Properties

checkDefaults?: boolean

Whether or not to look for existing values before using the defaults passed

default

true

checkGets?: boolean

Whether or not to check localStorage when an object key is retrieved

default

true

id?: string

An optional unique identifier. Prefixes all keys in localStorage with this id (eg. stores foo in localStorage as myid.foo for myid)

mutateProxiedObject?: boolean

Whether to modify values on the proxied object or leave it as-is. Doesn't do anything if passed with partial for storeObject

default

true

Methods

  • get(key: string): null | string
  • Called whenever a key should be retrieved

    Parameters

    • key: string

    Returns null | string

    The key's value

  • modify(value: Partial<O>, action: "get" | "set", key: Keys<O>): Partial<O>
  • Modify an object before setting it in localStorage or reading it. Called after validate. Any valiation should be done in validate and not here

    Parameters

    • value: Partial<O>

      A partial version of the originally passed object, containing only the key being get/set

    • action: "get" | "set"
    • key: Keys<O>

      The key being get/set

    Returns Partial<O>

    A potentially modified version of the object originally passed. Only the key used in the value param will be changed in localStorage

  • parse(value: string): any
  • Function to parse object. Defaults to JSON.parse. Any validation should NOT be done here, but in the validate method

    default

    JSON.parse

    Parameters

    • value: string

    Returns any

  • set(key: string, value: string): void
  • Called whenever a key should be set

    default

    localStorage.setItem

    Parameters

    • key: string
    • value: string

      The value being set

    Returns void

  • stringify(value: any): string
  • Function to stringify object. Defaults to JSON.stringify. Any validation should NOT be done here, but in the validate method

    default

    JSON.stringify

    Parameters

    • value: any

    Returns string

  • validate(value: Partial<O>, action: "get" | "set", key: Keys<O>): boolean | readonly [boolean] | readonly [false, Error]
  • Validate an object before setting it in localStorage or reading it. Can confirm/deny if the object is valid, along with an optional error message if it is invalid

    Parameters

    • value: Partial<O>

      A partial version of the originally passed object, containing only the key being get/set

    • action: "get" | "set"
    • key: Keys<O>

      The key being get/set

    Returns boolean | readonly [boolean] | readonly [false, Error]

    A boolean to confirm validity or false and optionally an Error instance to deny validity

Generated using TypeDoc