Trails Packages
    Preparing search index...

    Provides access to the browser's local storage for Open Pioneer Trails packages through a convenient API. Use the interface name "local-storage.LocalStorageService" to inject an instance of this interface.

    interface LocalStorageService {
        isSupported: boolean;
        get(key: string): unknown;
        getNamespace(key: string): LocalStorageAPI;
        remove(key: string): void;
        removeAll(): void;
        set(key: string, value: unknown): void;
    }

    Hierarchy (View Summary)

    Index

    Properties

    isSupported: boolean

    Whether local storage is supported by the current environment.

    Getters and setters working on local storage will throw if this value is false.

    Methods

    • Returns the value associated with the given key, or undefined if no such value exists.

      Parameters

      • key: string

      Returns unknown

    • Returns a storage namespace operating on the given key that can be used to group multiple related properties. key should either be associated with an object or it's value should be undefined. If key is not associated with a value, a new empty object will be created.

      Namespaces allow you to treat an object in local storage as a group of properties. Getting (or setting) a key using a Namespace object will simply read (or update) properties on the managed object instead.

      If key has already been set to something that is not an object, you will receive an error if you attempt to call this method.

      Example:

      const storageService = ...; // injected

      // Namespace operates on the "my-package-name" object (which may not exist yet)
      const packageNamespace = storageService.getNamespace("my-package-name");

      // Setting the first value will ensure that the object exists
      packageNamespace.set("foo", "bar"); // actually sets `"my-package-name" -> "foo"`

      // Retrieving the same object ("my-package-name") via get():
      const backingObject = storageService.get("my-package-name"); // {"foo": "bar"}
      console.log(backingObject);

      Parameters

      • key: string

      Returns LocalStorageAPI

    • Removes all entries associated managed by this instance.

      If this represents the root object, all entries will be removed. If this represents a (possibly nested) namespace, only the contents of that namespace will be removed.

      Returns void

    • Associates the given value with key.

      This method supports arbitrary JSON compatible values, including objects and arrays. If you store an object, you can later access (or modify) its individual properties using getNamespace.

      NOTE: This function creates a clone of the original value to protect against accidental side effects. Updating the original value after set() will have no effect on the stored value.

      Parameters

      • key: string
      • value: unknown

      Returns void