Options
All
  • Public
  • Public/Protected
  • All
Menu

h5webstorage

Index

Variables

BROWSER_STORAGE_PROVIDERS

BROWSER_STORAGE_PROVIDERS: Provider[] = [{ provide: LOCAL_STORAGE_OBJECT, useValue: localStorage },{ provide: SESSION_STORAGE_OBJECT, useValue: sessionStorage },{ provide: SERDES_OBJECT, useValue: { stringify: JSON.stringify, parse: JSON.parse } },ConfigureStorage({prefix: ""})]

The objects necessary to use Web Storage in the browser

LOCAL_STORAGE_OBJECT

LOCAL_STORAGE_OBJECT: OpaqueToken = new OpaqueToken("localstorage")

Token used to inject an object as the storage backend of the SessionStorage object. By default, the storage backend is the native localStorage object but can be substituted to allow for testing or customized storage like to remote storage.

SERDES_OBJECT

SERDES_OBJECT: OpaqueToken = new OpaqueToken("SerdesObject")

An object that SERializes and DESeriallizes values for storage. The default implementation for the SerDes object is: { provide: SERDES_OBJECT, useValue: { stringify: JSON.stringify, parse: JSON.parse } } which is essentially the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON" class="external">window.JSON</a> object. Due to the fact that the JSON object is also an interface in TypeScript, it couldn't be used as-is. This is the reason the default implementation defines the stringify and parse methods individually instead of just using the JSON object as the value.

Should you want to implement customized serialization and deserialization for something like encrypted storage, simply provide new methods for stringify and parse and you're good to go.

SESSION_STORAGE_OBJECT

SESSION_STORAGE_OBJECT: OpaqueToken = new OpaqueToken("sessionstorage")

Token used to inject an object as the storage backend of the SessionStorage object. By default, the storage backend is the native sessionStorage object but can be substituted to allow for testing or customized storage like to remote storage.

STORAGE_OPTIONS

STORAGE_OPTIONS: OpaqueToken = new OpaqueToken("StorageOptions")

The token used to allow injection of the StorageOptions interface. For more information visit the angular2 docs.

storageType

storageType: Array<string> = ["local", "session"]

Functions

ConfigureStorage

StorageProperty

  • StorageProperty(options: object): any
  • StorageProperty(storageKey?: string, storage?: "Local" | "Session"): any
  • A decorator that associates a property with a key in storage

    Parameters

    • options: object

      An object containing properties to determine how the property behaves

      • storageKey {string} [optional]: The name of the key in storage to use. If not supplied or null, the name of the property is used
      • storage ("Local" | "Session"): Chooses the type of storage to use (default: "Local")
      • readOnly {boolean}: determines if the property is read/write or readOnly (default: read/write)

      Example - How to use StorageProperty

      Default options with initialization

      export class TodoApp {
       //setup a default value. If a value is already defined, it will not be overwritten
      
       @StorageProperty()
       public settings: any = { list: "todolist", hideDoneItems: true };
      
       constructor(private localStorage: LocalStorage) {...}
      }
      

      Attach to SessionStorage with initialization

      export class TodoApp {
       //setup a default value. If a value is already defined, it will not be overwritten
      
       @StorageProperty({storage: "Session"})
       public settings: any = { list: "todolist", hideDoneItems: true };
      
       constructor(private sessionStorage: sessionStorage) {...}
      }
      

      Attached to 'mysettings' key instead of settings and is not write-able

      export class TodoApp {
       //setup a default value. If a value is already defined, it will not be overwritten
      
       @StorageProperty({readOnly: true, storageKey: "mysettings"})
       public settings: any = { list: "todolist", hideDoneItems: true };
      
       constructor(private localStorage: LocalStorage) {...}
      }
      
      • Optional readOnly?: boolean
      • Optional storage?: "Local" | "Session"
      • Optional storageKey?: string

    Returns any

  • Associates a property with a key in storage

    Parameters

    • Optional storageKey: string
    • Optional storage: "Local" | "Session"

    Returns any

createBacking

  • createBacking(type: string): (Anonymous function)

storageFactory

  • storageFactory(type: string): (Anonymous function)

Generated using TypeDoc