From 4fd99fec251c86bd826744fc39bb7d1bc2583072 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 2 Jun 2020 17:05:49 +0200 Subject: [PATCH] feat(core-api/Storage): reworking the api for storage. get's should be sync --- .../src/apis/definitions/StorageApi.ts | 61 ++++--------------- 1 file changed, 12 insertions(+), 49 deletions(-) diff --git a/packages/core-api/src/apis/definitions/StorageApi.ts b/packages/core-api/src/apis/definitions/StorageApi.ts index 0cb5ccc14d..62a8fd6895 100644 --- a/packages/core-api/src/apis/definitions/StorageApi.ts +++ b/packages/core-api/src/apis/definitions/StorageApi.ts @@ -15,77 +15,40 @@ */ import { createApiRef } from '../ApiRef'; - -type UnsubscribeFromStore = () => void; -type SubscribeToStoreHandler = ({ - storeName, - key, - oldValue, - newValue, -}: { - storeName: string; - key: string; - oldValue?: T; - newValue?: T; -}) => void; +import { Observable } from '@backstage/core-api'; export type StorageApi = { /** * Get persistent data. - * @param {String} storeName Name of the store. - * @param {String?} key (Optional) Unique key associated with the data. - * If not key is specified,the whole store is returned. - * @param {String} key (Optional) Empty value to return if there is not data. + * + * @param {String} key Unique key associated with the data. * @return {Object} data The data that should is stored. */ - getFromStore( - storeName: string, - key: string, - defaultValue?: T, - ): Promise; + get(key: string): T | undefined; /** * Remove persistent data. * - * @param {String} storeName Name of the store. * @param {String} key Unique key associated with the data. */ - removeFromStore(storeName: string, key: string): Promise; + remove(key: string): Promise; /** - * Save persiswtent data. + * Save persistant data. * - * @param {String} storeName Name of the store. * @param {String} key Unique key associated with the data. - * @param {Object} data The data that should be stored. + * @return */ - saveToStore(storeName: string, key: string, data: any): Promise; + save(key: string, data: any): Promise; /** - * Callback for Changes in the store - * @callback subscribeHandler - * @param {String} storeName Name of the store. - * @param {String} key Unique key associated with the data. - * @param {Object} oldValue The old value that was in the store. - * @param {Object} newValue The new value that has been set in the store. - */ - /** - * Subscribe to Key changes in a store and get the new and old value * - * @param {String} storeName Name of the store. - * @param {String} key Unique key associated with the data. - * @param {subscribeHandler} handler Handler which is called with the old value and new value in the store. - * @returns {Function} Unsubscribe to changes in the store. + * @param {String} key Unique key associated with the data */ - subscribeToChange( - storeName: string, - key: string, - handler: SubscribeToStoreHandler, - ): UnsubscribeFromStore; + observe$(key: string): Observable; }; export const storageApiRef = createApiRef({ - id: 'core.user.settings', - description: - 'Provides the ability to modify settings that are personalised to the user', + id: 'core.storage', + description: 'Provides the ability to store data which is unique to the user', });