@rune-hub/utils 1.0.0 → 1.1.0
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.
|
@@ -8,18 +8,18 @@ var persistentRune = require('../persistentRune/persistentRune.js');
|
|
|
8
8
|
|
|
9
9
|
const asIs = (v) => v;
|
|
10
10
|
function persistent(key, initial = null, params) {
|
|
11
|
-
var _a, _b
|
|
12
|
-
const ctx =
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const ctx = runeHub.Hub.ctx;
|
|
13
13
|
if (!ctx)
|
|
14
14
|
return initial;
|
|
15
|
-
const decode = ((
|
|
15
|
+
const decode = ((_a = params === null || params === void 0 ? void 0 : params.decode) !== null && _a !== void 0 ? _a : asIs);
|
|
16
16
|
const initDecode = (value = null) => {
|
|
17
17
|
return value === null ? initial : decode(value);
|
|
18
18
|
};
|
|
19
19
|
const persistentSlot = runeHub.slot(persistentRune.persistentRune(key, params === null || params === void 0 ? void 0 : params.storage));
|
|
20
20
|
let result = persistentSlot.value;
|
|
21
21
|
if (!ctx.inited) {
|
|
22
|
-
const encode = ((
|
|
22
|
+
const encode = ((_b = params === null || params === void 0 ? void 0 : params.encode) !== null && _b !== void 0 ? _b : asIs);
|
|
23
23
|
ctx.on('change', () => {
|
|
24
24
|
result = encode(ctx.cur);
|
|
25
25
|
persistentSlot.set(result);
|
|
@@ -4,18 +4,18 @@ import { persistentRune } from '../persistentRune/persistentRune.mjs';
|
|
|
4
4
|
|
|
5
5
|
const asIs = (v) => v;
|
|
6
6
|
function persistent(key, initial = null, params) {
|
|
7
|
-
var _a, _b
|
|
8
|
-
const ctx =
|
|
7
|
+
var _a, _b;
|
|
8
|
+
const ctx = Hub.ctx;
|
|
9
9
|
if (!ctx)
|
|
10
10
|
return initial;
|
|
11
|
-
const decode = ((
|
|
11
|
+
const decode = ((_a = params === null || params === void 0 ? void 0 : params.decode) !== null && _a !== void 0 ? _a : asIs);
|
|
12
12
|
const initDecode = (value = null) => {
|
|
13
13
|
return value === null ? initial : decode(value);
|
|
14
14
|
};
|
|
15
15
|
const persistentSlot = slot(persistentRune(key, params === null || params === void 0 ? void 0 : params.storage));
|
|
16
16
|
let result = persistentSlot.value;
|
|
17
17
|
if (!ctx.inited) {
|
|
18
|
-
const encode = ((
|
|
18
|
+
const encode = ((_b = params === null || params === void 0 ? void 0 : params.encode) !== null && _b !== void 0 ? _b : asIs);
|
|
19
19
|
ctx.on('change', () => {
|
|
20
20
|
result = encode(ctx.cur);
|
|
21
21
|
persistentSlot.set(result);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Rune } from 'rune-hub';
|
|
2
2
|
export type PersistentStorage = Record<string, string | null>;
|
|
3
|
-
export
|
|
3
|
+
export type PersistentStorageMapItem = Record<string, Rune<string | null>>;
|
|
4
|
+
export declare const persistentStorageMap: Map<PersistentStorage, PersistentStorageMapItem>;
|
|
4
5
|
export declare function persistentRune(key: string, storage?: PersistentStorage): Rune<string | null>;
|
|
@@ -5,15 +5,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var runeHub = require('rune-hub');
|
|
6
6
|
|
|
7
7
|
const persistentStorageMap = new Map();
|
|
8
|
-
function persistentRune(key, storage = typeof localStorage !== 'undefined' ? localStorage :
|
|
8
|
+
function persistentRune(key, storage = typeof localStorage !== 'undefined' ? localStorage : Object.create(null)) {
|
|
9
9
|
let map = persistentStorageMap.get(storage);
|
|
10
10
|
if (!map) {
|
|
11
|
-
persistentStorageMap.set(storage, map =
|
|
11
|
+
persistentStorageMap.set(storage, map = Object.create(null));
|
|
12
12
|
}
|
|
13
13
|
if (!map[key]) {
|
|
14
14
|
map[key] = () => {
|
|
15
|
-
|
|
16
|
-
const ctx = ((_a = runeHub.Hub.cur) !== null && _a !== void 0 ? _a : runeHub.Hub.root).ctx;
|
|
15
|
+
const ctx = runeHub.Hub.ctx;
|
|
17
16
|
if (!ctx)
|
|
18
17
|
return null;
|
|
19
18
|
if (!ctx.inited) {
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { Hub } from 'rune-hub';
|
|
2
2
|
|
|
3
3
|
const persistentStorageMap = new Map();
|
|
4
|
-
function persistentRune(key, storage = typeof localStorage !== 'undefined' ? localStorage :
|
|
4
|
+
function persistentRune(key, storage = typeof localStorage !== 'undefined' ? localStorage : Object.create(null)) {
|
|
5
5
|
let map = persistentStorageMap.get(storage);
|
|
6
6
|
if (!map) {
|
|
7
|
-
persistentStorageMap.set(storage, map =
|
|
7
|
+
persistentStorageMap.set(storage, map = Object.create(null));
|
|
8
8
|
}
|
|
9
9
|
if (!map[key]) {
|
|
10
10
|
map[key] = () => {
|
|
11
|
-
|
|
12
|
-
const ctx = ((_a = Hub.cur) !== null && _a !== void 0 ? _a : Hub.root).ctx;
|
|
11
|
+
const ctx = Hub.ctx;
|
|
13
12
|
if (!ctx)
|
|
14
13
|
return null;
|
|
15
14
|
if (!ctx.inited) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rune-hub/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Utils for rune-hub",
|
|
5
5
|
"author": "Mikhail Lysikov <d8corp@mail.ru>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
"lint:fix": "eslint --fix"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"rune-hub": "^1.
|
|
45
|
+
"rune-hub": "^1.1.0"
|
|
46
46
|
}
|
|
47
47
|
}
|