@yaasl/core 0.13.0-alpha.1 → 0.13.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/utils/get-scoped-key.d.ts +1 -0
- package/dist/cjs/effects/indexed-db.js +2 -1
- package/dist/cjs/effects/local-storage.js +2 -3
- package/dist/cjs/effects/session-storage.js +2 -3
- package/dist/cjs/utils/get-scoped-key.js +6 -0
- package/dist/esm/effects/indexed-db.js +2 -1
- package/dist/esm/effects/local-storage.js +2 -3
- package/dist/esm/effects/session-storage.js +2 -3
- package/dist/esm/utils/get-scoped-key.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getScopedKey: (key: string) => string;
|
|
@@ -13,11 +13,12 @@ exports.indexedDb = void 0;
|
|
|
13
13
|
const utils_1 = require("@yaasl/utils");
|
|
14
14
|
const create_effect_1 = require("./create-effect");
|
|
15
15
|
const base_1 = require("../base");
|
|
16
|
+
const get_scoped_key_1 = require("../utils/get-scoped-key");
|
|
16
17
|
const idb_store_1 = require("../utils/idb-store");
|
|
17
18
|
let atomDb = null;
|
|
18
19
|
const createSync = (storeKey, onTabSync) => {
|
|
19
20
|
var _a;
|
|
20
|
-
const observingKey = storeKey + "/last-change";
|
|
21
|
+
const observingKey = (0, get_scoped_key_1.getScopedKey)(storeKey) + "/last-change";
|
|
21
22
|
let changeTrigger = null;
|
|
22
23
|
(_a = (0, utils_1.getWindow)()) === null || _a === void 0 ? void 0 : _a.addEventListener("storage", ({ key }) => {
|
|
23
24
|
if (observingKey !== key)
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.localStorage = void 0;
|
|
4
4
|
const utils_1 = require("@yaasl/utils");
|
|
5
5
|
const create_effect_1 = require("./create-effect");
|
|
6
|
-
const
|
|
6
|
+
const get_scoped_key_1 = require("../utils/get-scoped-key");
|
|
7
7
|
const string_storage_1 = require("../utils/string-storage");
|
|
8
8
|
const syncOverBrowserTabs = (observingKey, onTabSync) => {
|
|
9
9
|
var _a;
|
|
@@ -25,8 +25,7 @@ const syncOverBrowserTabs = (observingKey, onTabSync) => {
|
|
|
25
25
|
**/
|
|
26
26
|
exports.localStorage = (0, create_effect_1.createEffect)(({ atom, options = {} }) => {
|
|
27
27
|
var _a;
|
|
28
|
-
const
|
|
29
|
-
const { key = internalKey, parser, noTabSync } = options;
|
|
28
|
+
const { key = (0, get_scoped_key_1.getScopedKey)(atom.name), parser, noTabSync } = options;
|
|
30
29
|
const storage = new string_storage_1.StringStorage({
|
|
31
30
|
key,
|
|
32
31
|
store: (_a = (0, utils_1.getWindow)()) === null || _a === void 0 ? void 0 : _a.localStorage,
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.sessionStorage = void 0;
|
|
4
4
|
const utils_1 = require("@yaasl/utils");
|
|
5
5
|
const create_effect_1 = require("./create-effect");
|
|
6
|
-
const
|
|
6
|
+
const get_scoped_key_1 = require("../utils/get-scoped-key");
|
|
7
7
|
const string_storage_1 = require("../utils/string-storage");
|
|
8
8
|
/** Middleware to save and load atom values to the session storage.
|
|
9
9
|
*
|
|
@@ -17,8 +17,7 @@ const string_storage_1 = require("../utils/string-storage");
|
|
|
17
17
|
**/
|
|
18
18
|
exports.sessionStorage = (0, create_effect_1.createEffect)(({ atom, options = {} }) => {
|
|
19
19
|
var _a;
|
|
20
|
-
const
|
|
21
|
-
const { key = internalKey, parser } = options;
|
|
20
|
+
const { key = (0, get_scoped_key_1.getScopedKey)(atom.name), parser } = options;
|
|
22
21
|
const storage = new string_storage_1.StringStorage({
|
|
23
22
|
key,
|
|
24
23
|
store: (_a = (0, utils_1.getWindow)()) === null || _a === void 0 ? void 0 : _a.sessionStorage,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getScopedKey = void 0;
|
|
4
|
+
const base_1 = require("../base");
|
|
5
|
+
const getScopedKey = (key) => base_1.CONFIG.name ? `${base_1.CONFIG.name}/${key}` : key;
|
|
6
|
+
exports.getScopedKey = getScopedKey;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { getWindow } from "@yaasl/utils";
|
|
2
2
|
import { createEffect } from "./create-effect";
|
|
3
3
|
import { CONFIG } from "../base";
|
|
4
|
+
import { getScopedKey } from "../utils/get-scoped-key";
|
|
4
5
|
import { IdbStore } from "../utils/idb-store";
|
|
5
6
|
let atomDb = null;
|
|
6
7
|
const createSync = (storeKey, onTabSync) => {
|
|
7
|
-
const observingKey = storeKey + "/last-change";
|
|
8
|
+
const observingKey = getScopedKey(storeKey) + "/last-change";
|
|
8
9
|
let changeTrigger = null;
|
|
9
10
|
getWindow()?.addEventListener("storage", ({ key }) => {
|
|
10
11
|
if (observingKey !== key)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getWindow } from "@yaasl/utils";
|
|
2
2
|
import { createEffect } from "./create-effect";
|
|
3
|
-
import {
|
|
3
|
+
import { getScopedKey } from "../utils/get-scoped-key";
|
|
4
4
|
import { StringStorage } from "../utils/string-storage";
|
|
5
5
|
const syncOverBrowserTabs = (observingKey, onTabSync) => getWindow()?.addEventListener("storage", ({ key, newValue }) => {
|
|
6
6
|
if (observingKey !== key)
|
|
@@ -18,8 +18,7 @@ const syncOverBrowserTabs = (observingKey, onTabSync) => getWindow()?.addEventLi
|
|
|
18
18
|
* @returns The effect to be used on atoms.
|
|
19
19
|
**/
|
|
20
20
|
export const localStorage = createEffect(({ atom, options = {} }) => {
|
|
21
|
-
const
|
|
22
|
-
const { key = internalKey, parser, noTabSync } = options;
|
|
21
|
+
const { key = getScopedKey(atom.name), parser, noTabSync } = options;
|
|
23
22
|
const storage = new StringStorage({
|
|
24
23
|
key,
|
|
25
24
|
store: getWindow()?.localStorage,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getWindow } from "@yaasl/utils";
|
|
2
2
|
import { createEffect } from "./create-effect";
|
|
3
|
-
import {
|
|
3
|
+
import { getScopedKey } from "../utils/get-scoped-key";
|
|
4
4
|
import { StringStorage } from "../utils/string-storage";
|
|
5
5
|
/** Middleware to save and load atom values to the session storage.
|
|
6
6
|
*
|
|
@@ -13,8 +13,7 @@ import { StringStorage } from "../utils/string-storage";
|
|
|
13
13
|
* @returns The effect to be used on atoms.
|
|
14
14
|
**/
|
|
15
15
|
export const sessionStorage = createEffect(({ atom, options = {} }) => {
|
|
16
|
-
const
|
|
17
|
-
const { key = internalKey, parser } = options;
|
|
16
|
+
const { key = getScopedKey(atom.name), parser } = options;
|
|
18
17
|
const storage = new StringStorage({
|
|
19
18
|
key,
|
|
20
19
|
store: getWindow()?.sessionStorage,
|