diff --git a/CHANGELOG.md b/CHANGELOG.md
index 90cc6d5..acb71e1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+## [2.4.1]
+
+### Fixed
+
+- Shared storage eagerly created, nullify the purpose of `disableWarnings` ([Issue#56])
+
## [2.4.0]
### Added
@@ -127,6 +133,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `sessionStorage()` use `createSessionStorage()` instead
- `indexedDBStorage()` use `createIndexedDBStorage()` instead
+## Versions 1.x
+
+
## [1.3.0]
### Added
@@ -187,7 +196,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
First version
-[Unreleased]: https://github.com/MacFJA/svelte-persistent-store/compare/2.4.0...HEAD
+
+
+[Unreleased]: https://github.com/MacFJA/svelte-persistent-store/compare/2.4.1...HEAD
+[2.4.1]: https://github.com/MacFJA/svelte-persistent-store/compare/2.4.0...2.4.1
[2.4.0]: https://github.com/MacFJA/svelte-persistent-store/compare/2.3.2...2.4.0
[2.3.2]: https://github.com/MacFJA/svelte-persistent-store/compare/2.3.1...2.3.2
[2.3.1]: https://github.com/MacFJA/svelte-persistent-store/compare/2.3.0...2.3.1
@@ -220,6 +232,7 @@ First version
[Issue#48]: https://github.com/MacFJA/svelte-persistent-store/issues/48
[Issue#50]: https://github.com/MacFJA/svelte-persistent-store/issues/50
[Issue#52]: https://github.com/MacFJA/svelte-persistent-store/issues/52
+[Issue#56]: https://github.com/MacFJA/svelte-persistent-store/issues/56
[PR#8]: https://github.com/MacFJA/svelte-persistent-store/pull/8
[PR#38]: https://github.com/MacFJA/svelte-persistent-store/pull/38
[PR#39]: https://github.com/MacFJA/svelte-persistent-store/pull/39
diff --git a/package-lock.json b/package-lock.json
index 44c6cc6..8987c50 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@macfja/svelte-persistent-store",
- "version": "2.4.0",
+ "version": "2.4.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@macfja/svelte-persistent-store",
- "version": "2.4.0",
+ "version": "2.4.1",
"license": "MIT",
"dependencies": {
"@macfja/serializer": "^1.1.2",
diff --git a/package.json b/package.json
index 333b454..1d56a79 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@macfja/svelte-persistent-store",
- "version": "2.4.0",
+ "version": "2.4.1",
"description": "A Svelte store that keep its value through pages and reloads",
"main": "dist/index.js",
"module": "dist/index.mjs",
diff --git a/src/alias.ts b/src/alias.ts
index 0da6926..23025be 100644
--- a/src/alias.ts
+++ b/src/alias.ts
@@ -4,9 +4,25 @@ import type { Writable, StartStopNotifier } from "svelte/store"
import type { PersistentStore, StorageInterface } from "./core"
import { createCookieStorage, createLocalStorage, createSessionStorage, persist } from "./core"
-const sharedCookieStorage = createCookieStorage(),
- sharedLocalStorage: StorageInterface = createLocalStorage(),
- sharedSessionStorage: StorageInterface = createSessionStorage()
+type StorageType = "cookie" | "local" | "session"
+const sharedStorage: { [type in StorageType]?: StorageInterface } = {}
+
+function getStorage(type: StorageType): StorageInterface {
+ if (!Object.keys(sharedStorage).includes(type)) {
+ switch (type) {
+ case "cookie":
+ sharedStorage[type] = createCookieStorage()
+ break
+ case "local":
+ sharedStorage[type] = createLocalStorage()
+ break
+ case "session":
+ sharedStorage[type] = createSessionStorage()
+ break
+ }
+ }
+ return sharedStorage[type] as StorageInterface
+}
/**
* Persist a store into a cookie
@@ -14,7 +30,7 @@ const sharedCookieStorage = createCookieStorage(),
* @param {string} cookieName The name of the cookie
*/
export function persistCookie(store: Writable, cookieName: string): PersistentStore {
- return persist(store, sharedCookieStorage, cookieName)
+ return persist(store, getStorage("cookie"), cookieName)
}
/**
* Persist a store into the browser session storage
@@ -22,7 +38,7 @@ export function persistCookie(store: Writable, cookieName: string): Persis
* @param {string} key The name of the key in the browser session storage
*/
export function persistBrowserSession(store: Writable, key: string): PersistentStore {
- return persist(store, sharedSessionStorage, key)
+ return persist(store, getStorage("session"), key)
}
/**
* Persist a store into the browser local storage
@@ -30,7 +46,7 @@ export function persistBrowserSession(store: Writable, key: string): Persi
* @param {string} key The name of the key in the browser local storage
*/
export function persistBrowserLocal(store: Writable, key: string): PersistentStore {
- return persist(store, sharedLocalStorage, key)
+ return persist(store, getStorage("local"), key)
}
/**