From c192586e9e3c5180e271dbd21e7295aaf1dcdbb6 Mon Sep 17 00:00:00 2001 From: Stephen Lautier Date: Thu, 17 Sep 2015 00:43:21 +0200 Subject: [PATCH] changes: - added default export for localforage module (for style es6 imports) - added createInstance method - some minor doc - changed driver to accept also a string (to use their property e.g. localforage.LOCALSTORAGE - added some minor tests --- localForage/localForage-tests.ts | 10 ++++++++++ localForage/localForage.d.ts | 19 +++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/localForage/localForage-tests.ts b/localForage/localForage-tests.ts index bb824b7312..6f162e8c4b 100644 --- a/localForage/localForage-tests.ts +++ b/localForage/localForage-tests.ts @@ -52,4 +52,14 @@ declare var localForage: LocalForage; localForage.removeItem("key").then(() => { }); + + var config = localForage.config({ + name: "testyo", + driver: localForage.LOCALSTORAGE + }); + + var store = localForage.createInstance({ + name: "da instance", + driver: localForage.LOCALSTORAGE + }); } \ No newline at end of file diff --git a/localForage/localForage.d.ts b/localForage/localForage.d.ts index d169d01e3f..cd12bb4f32 100644 --- a/localForage/localForage.d.ts +++ b/localForage/localForage.d.ts @@ -6,7 +6,7 @@ /// interface LocalForageOptions { - driver?: LocalForageDriver | LocalForageDriver[]; + driver?: string | LocalForageDriver | LocalForageDriver[]; name?: string; @@ -46,9 +46,19 @@ interface LocalForage { WEBSQL: string; INDEXEDDB: string; - config(options: LocalForageOptions): void; + /** + * Set and persist localForage options. This must be called before any other calls to localForage are made, but can be called after localForage is loaded. + * If you set any config values with this method they will persist after driver changes, so you can call config() then setDriver() + * @param {ILocalForageConfig} options? + */ + config(options: LocalForageOptions): boolean; + createInstance(options: LocalForageOptions): LocalForage; driver(): LocalForageDriver; + /** + * Force usage of a particular driver or drivers, if available. + * @param {string} driver + */ setDriver(driver: string | string[]): Promise; setDriver(driver: string | string[], callback: () => void, errorCallback: (error: any) => void): void; defineDriver(driver: LocalForageDriver): Promise; @@ -79,3 +89,8 @@ interface LocalForage { iterate(iteratee: (value: any, key: string, iterationNumber: number) => any, callback: (err: any, result: any) => void): void; } + +declare module "localforage" { + var localforage: LocalForage; + export default localforage; +} \ No newline at end of file