diff --git a/index.d.ts b/index.d.ts index 45a714640..22f2748b8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3568,40 +3568,28 @@ declare namespace Backbone { * Add new storage * @example * storageManager.add('local2', { - * load: function(keys, clb, clbErr) { - * var res = {}; - * for (var i = 0, len = keys.length; i < len; i++){ - * var v = localStorage.getItem(keys[i]); - * if(v) res[keys[i]] = v; - * } - * clb(res); // might be called inside some async method - * // In case of errors... - * // clbErr('Went something wrong'); + * async load(storageOptions) { + * // ... + * }, + * async store(data, storageOptions) { + * // ... * }, - * store: function(data, clb, clbErr) { - * for(var key in data) - * localStorage.setItem(key, data[key]); - * clb(); // might be called inside some async method - * } * }); * @param id - Storage ID * @param storage - Storage wrapper * @param storage.load - Load method * @param storage.store - Store method */ - add(id: string, storage: { - load: (...params: any[]) => any; - store: (...params: any[]) => any; - }): this; + add(id: string, storage: IStorage): this; /** * Returns storage by id * @param id - Storage ID */ - get(id: string): any | null; + get(id: string): IStorage | null; /** * Returns all storages */ - getStorages(): any[]; + getStorages(): Record; /** * Returns current storage type */ @@ -3612,30 +3600,41 @@ declare namespace Backbone { */ setCurrent(id: string): this; /** - * Store key-value resources in the current storage + * Store data in the current storage. + * @param data Project data. + * @param options Storage options. + * @returns Stored data. * @example - * storageManager.store({item1: value1, item2: value2}); - * @param data - Data in key-value format, eg. {item1: value1, item2: value2} - * @param clb - Callback function + * const data = editor.getProjectData(); + * await storageManager.store(data); */ - store(data: any, clb: (...params: any[]) => any): any | null; + store(data: ProjectData, options: StorageOptions): Promise; /** * Load resource from the current storage by keys + * @param options Storage options. + * @returns Loaded data. * @example - * storageManager.load(['item1', 'item2'], res => { - * // res -> {item1: value1, item2: value2} - * }); - * storageManager.load('item1', res => { - * // res -> {item1: value1} - * }); - * @param keys - Keys to load - * @param clb - Callback function - */ - load(keys: string | string[], clb: (...params: any[]) => any): void; + * const data = await storageManager.load(); + * editor.loadProjectData(data); + * */ + load(options: StorageOptions): Promise; /** * Get current storage */ - getCurrentStorage(): Storage; + getCurrentStorage(): IStorage; + } + + interface ProjectData { + + } + + interface StorageOptions { + + } + + interface IStorage { + load: (options: StorageOptions) => Promise; + store: (data: ProjectData, options: StorageOptions) => Promise; } /** diff --git a/src/storage_manager/model/LocalStorage.js b/src/storage_manager/model/LocalStorage.js index a8f57e20f..dd70a6235 100644 --- a/src/storage_manager/model/LocalStorage.js +++ b/src/storage_manager/model/LocalStorage.js @@ -1,7 +1,6 @@ -import { Model } from 'common'; import { hasWin } from 'utils/mixins'; -export default class LocalStorage extends Model { +export default class LocalStorage { async store(data, opts = {}) { if (this.hasLocal(opts, true)) { localStorage.setItem(opts.key, JSON.stringify(data)); diff --git a/src/storage_manager/model/RemoteStorage.js b/src/storage_manager/model/RemoteStorage.js index 4540d9688..d4c6b4f0a 100644 --- a/src/storage_manager/model/RemoteStorage.js +++ b/src/storage_manager/model/RemoteStorage.js @@ -1,8 +1,7 @@ import fetch from 'utils/fetch'; -import { Model } from 'common'; import { isUndefined, isFunction, isString } from 'underscore'; -export default class RemoteStorage extends Model { +export default class RemoteStorage { async store(data, opts = {}) { await this.request(opts.urlStore, this.__props(opts, data), opts); }