Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TypedSettingProps<SettingsType>

A wrapper to make it easier to work with Fitbit Setting API.

Behind the scene, the wrapper 'packs' and 'unpacks' settings into / from strings, and persists to the props.settingsStorage, so that users don't need to do that in their codes. By default, 'packs' always uses JSON.stringify() to encode settings, even if the value is a string, and 'unpacks' always attempts to decode strings with JSON.parse() and, if that fails, return the strings as is. The packing and unpacking behaviours can be customised.

Receives an optional generic type SettingsType, which is the type of the unpacked settings.

Type parameters

  • SettingsType: object

Hierarchy

  • TypedSettingProps

Index

Constructors

constructor

  • Construct a wrapper of the 'props', and optionally customise the packing / unpacking behaviour of the wrapper.

    Parameters

    • props: SettingsComponentProps

      the 'props' parameter received by the JSX

    • Optional packerUnpackers: PackerUnpackerOption<SettingsType>

      option to customise wrapper's packing / unpacking / initialization behaviour for individual properties of the settings. See PackerUnpackerOption for more details.

    • Optional defaultPackerUnpacker: DefaultPackerUnpackerOption

    Returns TypedSettingProps

Properties

Private Readonly accessedRegistry

accessedRegistry: Set<string> = new Set<string>()

Private Readonly defaultPacker

defaultPacker: (value: NonUndefined<any>) => string

Type declaration

Private Readonly defaultUnpackInitiator

defaultUnpackInitiator: (settings: string) => unknown

Type declaration

    • (settings: string): unknown
    • Parameters

      • settings: string

      Returns unknown

Private Optional packerUnpackers

packerUnpackers: PackerUnpackerOption<SettingsType>

option to customise wrapper's packing / unpacking / initialization behaviour for individual properties of the settings. See PackerUnpackerOption for more details.

Private props

the 'props' parameter received by the JSX

Private Readonly trackedSettings

trackedSettings: {}

Type declaration

  • [k: string]: unknown

Private Readonly typedSettings

typedSettings: {}

Type declaration

  • [k: string]: unknown

Methods

commit

  • commit(): void
  • update all the properties that has been accessed through getToUpdate() to the settingsStorage

    Returns void

get

  • get(): Readonly<SettingsType>
  • Get a typed, readonly copy of the settings. To update the settings, use 'update' method.

    Returns Readonly<SettingsType>

getToUpdate

  • getToUpdate(): Readonly<SettingsType>
  • Returns a tracked setting object. When accessing a property of the tracked setting object through a key, the key is marked as 'dirty', meaning it's assumed that the property is changed and needs to be persisted to settingsStorage later. In the end the commit() method of the wrapper needs to be called to persist all the 'dirty' properties.

    Returns Readonly<SettingsType>

Private persist

  • persist(key: string, val: any): void
  • Persist key & value to settingsStorage, value cannot be ASIS

    Parameters

    • key: string
    • val: any

    Returns void

Private track

  • track(key: string): void
  • install a tracker to trackedSettings to track access

    Parameters

    • key: string

    Returns void

update

  • update(value: Partial<{}>): void
  • Takes a partial settings, then updates the settings and takes care of preserving the updates in settingStorage.

    The value of a property of the partial settings can also be the constant ASIS, which is defined in this package. This denotes that the value of the property in the setting object is to be used as is.

    Parameters

    • value: Partial<{}>

      a partial SettingsType object

    Returns void

Generated using TypeDoc