@aws-amplify/core
Version:
Core category of aws-amplify
54 lines (53 loc) • 2.2 kB
TypeScript
import { KeyValueStorageEvent, KeyValueStorageInterface } from '../types';
/**
* @internal
*/
export declare class KeyValueStorage implements KeyValueStorageInterface {
storage?: Storage;
listeners?: Set<(e: KeyValueStorageEvent) => Promise<void>>;
/**
* The bound `window` 'storage' event handler. It is created lazily on the
* first successful browser subscription and cleared once the last listener
* unsubscribes. Instances that never subscribe therefore carry no
* function-valued own property, which keeps two structurally-identical
* storage instances deep-equal for consumers that compare by value (e.g.
* Jest's `toHaveBeenCalledWith`).
*/
private storageListener?;
constructor(storage?: Storage);
/**
* This is used to set a specific item in storage
* @param {string} key - the key for the item
* @param {object} value - the value
* @returns {string} value that was set
*/
setItem(key: string, value: string): Promise<void>;
/**
* This is used to get a specific key from storage
* @param {string} key - the key for the item
* This is used to clear the storage
* @returns {string} the data item
*/
getItem(key: string): Promise<string | null>;
/**
* This is used to remove an item from storage
* @param {string} key - the key being set
* @returns {string} value - value that was deleted
*/
removeItem(key: string): Promise<void>;
/**
* This is used to clear the storage
* @returns {string} nothing
*/
clear(): Promise<void>;
/**
* This is used to allow listening for changes
* @param {function} listener - the function called on storage change
* @returns {function} an unsubscribe function that removes the listener. The
* underlying `window` 'storage' event listener is attached lazily on the
* first subscription and detached once the last listener unsubscribes. In
* non-browser (SSR/native) environments nothing is attached and the returned
* unsubscribe function is a safe no-op.
*/
addListener(listener: (ev: KeyValueStorageEvent) => Promise<void>): () => void;
}