Options
All
  • Public
  • Public/Protected
  • All
Menu

hashed-es6

Index

Type aliases

FieldConfig

FieldConfig: { default: any; deserialize: (v: string) => any; serialize: (v: any) => string } | string | number | Date | boolean | any[]

Configuration for a field.

Can either be natively serializable type (string, number, Date, or boolean) or must be an object with a default, serialize, and deserialize members.

ProviderCallback

ProviderCallback: (values: Record<string, any>) => void

Callback for handling when the hash has changed.

param

Values that have changed.

Type declaration

    • (values: Record<string, any>): void
    • Parameters

      • values: Record<string, any>

      Returns void

SchemaConfig

SchemaConfig: Record<string, FieldConfig> & { _?: string }

Configuration for a Schema.

Is a dictionary of name to field.

Functions

register

  • Register a new state provider.

    remarks

    Components that want to initialize their state by deserializing values from the URL hash or persist their state by serializing values to the URL hash register themselves by calling register. Multiple components (that may not know about one another) can register for "slots" in the hash.

    Without custom serializers or deserializers, the config is an objects with property values representing the default state. For example, if your state is represented by a "start" date of Jan 1, 2000 and a "count" value of 42, your config would look like this:

    const config = {
      start: new Date(Date.UTC(2000, 0, 1)),
      count: 42
    };
    

    If you don't want to use the build-in functions for serializing and deserializing values, use an object with default, serialize, and deserialize properties. The default value represents the default value (if none is present in the URL). The serialize function is called with your state value and returns a string for the URL. The deserialize function is called with a string and returns the value for your state.

    Parameters

    • config: SchemaConfig

      Definition for the state "schema" (default values and types for each field). The config object takes two forms, depending on whether or not you want the default serializers and deserializers.

    • callback: ProviderCallback

      A function that is called when the URL hash is updated. The object properties represent new state values. The object will not include property values that have not changed.

    Returns ProviderCallback

    A function that should be called whenever a component's state changes. The URL hash will be updated with serialized versions of the state values.

reset

  • reset(): void
  • Clear all providers and state.

    Returns void

serialize

  • serialize(values: Record<string, any>): string
  • Serialize values as they would be represented in the hash.

    Parameters

    • values: Record<string, any>

      An object with values to be serialized.

    Returns string

    The values as they would be represented in the hash.

unregister

  • Unregister an existing state provider.

    Parameters

    Returns void

Generated using TypeDoc