diff --git a/packages/core-api/src/apis/definitions/StorageApi.ts b/packages/core-api/src/apis/definitions/StorageApi.ts index 90c1961588..7d7533f5b4 100644 --- a/packages/core-api/src/apis/definitions/StorageApi.ts +++ b/packages/core-api/src/apis/definitions/StorageApi.ts @@ -17,21 +17,21 @@ import { createApiRef } from '../ApiRef'; import { Observable } from '../../types'; -export type ObservableMessage = { +export type ObservableMessage = { key: string; newValue?: T; }; export interface StorageApi { /** - * The names + * Create a bucket to store data in. * @param {String} name Namespace for the storage to be stored under, * will inherit previous namespaces too */ forBucket(name: string): StorageApi; /** - * Get persistent data. + * Get the current value for persistent data, use observe$ to be notified of updates. * * @param {String} key Unique key associated with the data. * @return {Object} data The data that should is stored. @@ -46,17 +46,17 @@ export interface StorageApi { remove(key: string): Promise; /** - * Save persistant data. + * Save persistant data, and emit messages to anyone that is using observe$ for this key * * @param {String} key Unique key associated with the data. */ set(key: string, data: any): Promise; /** - * + * Observe changes on a particular key in the bucket * @param {String} key Unique key associated with the data */ - observe$(key: string): Observable; + observe$(key: string): Observable>; } export const storageApiRef = createApiRef({ diff --git a/packages/core-api/src/apis/implementations/StorageApi/WebStorage.ts b/packages/core-api/src/apis/implementations/StorageApi/WebStorage.ts index a7150b3647..c9665253de 100644 --- a/packages/core-api/src/apis/implementations/StorageApi/WebStorage.ts +++ b/packages/core-api/src/apis/implementations/StorageApi/WebStorage.ts @@ -48,17 +48,15 @@ export class WebStorage implements StorageApi { this.notifyChanges({ key, newValue: undefined }); } - observe$(key: string): Observable { - return this.observable.filter( - ({ key: messageKey }) => messageKey === key, - ) as Observable; + observe$(key: string): Observable> { + return this.observable.filter(({ key: messageKey }) => messageKey === key); } private getKeyName(key: string) { return `${this.namespace}/${key}`; } - private notifyChanges(message: ObservableMessage) { + private notifyChanges(message: ObservableMessage) { for (const subscription of this.subscribers) { subscription.next(message); }