sifrr / sifrr

:zap: Set of tiny, independent libraries for creating modern and fast webapps with javascript/typescript
https://sifrr.github.io/sifrr/
MIT License
332 stars 20 forks source link

getStorage function happens error !!! #415

Open ZhangDaZongWei opened 3 years ago

ZhangDaZongWei commented 3 years ago

the detail of the code:

import { getStorage } from '@sifrr/storage';

// Options with default values
let options = {
  priority: ['indexeddb', 'websql', 'localstorage', 'cookies', 'jsonstorage'], // Priority Array of type of storages to use
  name: 'SifrrStorage', // name of table (treat this as a variable name, i.e. no Spaces or special characters allowed)
  version: 1, // version number (integer / float / string), 1 is treated same as '1'
  desciption: 'Sifrr Storage', // description (text)
  size: 5 * 1024 * 1024, // Max db size in bytes only for websql (integer)
  ttl: 0 // Time to live/expire for data in table (in ms), 0 = forever, data will expire ttl ms after saving
};
export const cache = getStorage(options);

then

cache.ts:12 Uncaught TypeError: (0 , _sifrr_storage__WEBPACK_IMPORTED_MODULE_0__.getStorage) is not a function
    at Module../src/utils/cache.ts (cache.ts:12)
    at __webpack_require__ (bootstrap:21)
    at fn (hot module replacement:61)
    at Module../src/store/formVision.ts (main.bundle.js:26280)
    at __webpack_require__ (bootstrap:21)
    at fn (hot module replacement:61)
    at Module../src/store/register.ts (main.bundle.js:26472)
    at __webpack_require__ (bootstrap:21)
    at fn (hot module replacement:61)
    at Module../src/preset/preset.tsx (index.ts:1)

Looking forward to your reply! thanks!

BossBele commented 2 years ago

+1

zuiidea commented 2 years ago

@sifrr/storage@0.0.9 Type definition error, you can add a declaration file to solve it temporarily

declare type MainOptions = StorageOptions & { priority?: string[]; };

declare module '@sifrr/storage' { interface Sifrr { Storage: { getStorage: (options: MainOptions) => Storage; }; }

export const Sifrr: Sifrr; }


you can use like this
```js
import { Sifrr } from '@sifrr/storage';

const storage = Sifrr.Storage.getStorage({
...
});