Options
All
  • Public
  • Public/Protected
  • All
Menu

Provides asynchronous data storage.

Hierarchy

  • Store

Index

Methods

  • delete(key: string): Promise<void>
  • Removes an item from the Store.

    example
    import { user } from '../data/user';

    const store = stores.utils.withPrefix(stores.localStore(), user.guid);

    export async function resetTermsAndConditions() {
    return await store.delete('terms_accepted')
    .catch(errors.rethrow({ tags: ['legal'] }));
    }

    Parameters

    • key: string

      The item to remove.

    Returns Promise<void>

    A Promise that will be resolved when the item is removed from storage successfully or if the item is not found. This promise should only be rejected if the delete operation fails.

  • get(key: string): Promise<any>
  • Retrieves data from the Store.

    example
    import { user } from '../data/user';

    const store = stores.utils.withPrefix(stores.localStore(), user.guid);

    function defaultFalse(result) {
    return (result === undefined) ? false : result;
    }

    export async function termsAccepted() {
    return await store.get('terms_accepted')
    .then(defaultFalse)
    .catch(errors.rethrow({ tags: ['legal'] }));
    }

    Parameters

    • key: string

      The item to retrieve from storage.

    Returns Promise<any>

    A promise that will be resolved with the value of the item in storage (or undefined, if the item does not exist), or rejected if an error occurs.

  • set(key: string, value: any): Promise<any>
  • Puts data into the Store.

    example
    import { user } from '../data/user';

    const store = stores.utils.withPrefix(stores.localStore(), user.guid);

    export async function markTermsAndConditionsRead() {
    return await store.set('terms_accepted', true)
    .catch(errors.rethrow({ tags: ['legal'] }));
    }

    Parameters

    • key: string

      The key that uniquely identifies the item to store.

    • value: any

      The value to store under the associated key.

    Returns Promise<any>

    A Promise that will be resolved with the key when the item is stored, or rejected if the storage operation fails.