@efficimo/storage-react 0.0.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.
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/useStorageObservable.d.ts +7 -0
- package/dist/cjs/useStorageObservable.d.ts.map +1 -0
- package/dist/cjs/useStorageObservable.js +17 -0
- package/dist/cjs/useStorageObservable.js.map +1 -0
- package/dist/cjs/useStorageSerializedObservable.d.ts +7 -0
- package/dist/cjs/useStorageSerializedObservable.d.ts.map +1 -0
- package/dist/cjs/useStorageSerializedObservable.js +17 -0
- package/dist/cjs/useStorageSerializedObservable.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/useStorageObservable.d.ts +7 -0
- package/dist/esm/useStorageObservable.d.ts.map +1 -0
- package/dist/esm/useStorageObservable.js +14 -0
- package/dist/esm/useStorageObservable.js.map +1 -0
- package/dist/esm/useStorageSerializedObservable.d.ts +7 -0
- package/dist/esm/useStorageSerializedObservable.d.ts.map +1 -0
- package/dist/esm/useStorageSerializedObservable.js +14 -0
- package/dist/esm/useStorageSerializedObservable.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useStorageObservable"), exports);
|
|
18
|
+
__exportStar(require("./useStorageSerializedObservable"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,mEAAiD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { StorageObservable } from "@efficimo/storage";
|
|
2
|
+
/**
|
|
3
|
+
* Subscribes to a StorageObservable and returns a [value, setter] tuple,
|
|
4
|
+
* re-rendering the component whenever the storage value changes.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useStorageObservable<K extends string>(obs: StorageObservable<K>): [string | null, (value: string | null) => void];
|
|
7
|
+
//# sourceMappingURL=useStorageObservable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStorageObservable.d.ts","sourceRoot":"","sources":["../../src/useStorageObservable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG3D;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EACnD,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACxB,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC,CASjD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useStorageObservable = useStorageObservable;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/**
|
|
6
|
+
* Subscribes to a StorageObservable and returns a [value, setter] tuple,
|
|
7
|
+
* re-rendering the component whenever the storage value changes.
|
|
8
|
+
*/
|
|
9
|
+
function useStorageObservable(obs) {
|
|
10
|
+
const [value, setValue] = (0, react_1.useState)(() => obs.getValue());
|
|
11
|
+
(0, react_1.useEffect)(() => {
|
|
12
|
+
const subscription = obs.subscribe((v) => setValue(v));
|
|
13
|
+
return () => subscription.unsubscribe();
|
|
14
|
+
}, [obs]);
|
|
15
|
+
return [value, (v) => obs.next(v)];
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=useStorageObservable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStorageObservable.js","sourceRoot":"","sources":["../../src/useStorageObservable.ts"],"names":[],"mappings":";;AAOA,oDAWC;AAjBD,iCAA4C;AAE5C;;;GAGG;AACH,SAAgB,oBAAoB,CAClC,GAAyB;IAEzB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAgB,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IAExE,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,YAAY,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;IAC1C,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAEV,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { JsonSerializeObservableValue } from "@efficimo/observable";
|
|
2
|
+
/**
|
|
3
|
+
* Subscribes to a JsonSerializeObservableValue (from BaseStorage.getSerializedObservable)
|
|
4
|
+
* and returns a typed [value, setter] tuple.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useStorageSerializedObservable<T>(obs: JsonSerializeObservableValue<T>): [T | null, (value: T | null) => void];
|
|
7
|
+
//# sourceMappingURL=useStorageSerializedObservable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStorageSerializedObservable.d.ts","sourceRoot":"","sources":["../../src/useStorageSerializedObservable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAGzE;;;GAGG;AACH,wBAAgB,8BAA8B,CAAC,CAAC,EAC9C,GAAG,EAAE,4BAA4B,CAAC,CAAC,CAAC,GACnC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC,CASvC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useStorageSerializedObservable = useStorageSerializedObservable;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/**
|
|
6
|
+
* Subscribes to a JsonSerializeObservableValue (from BaseStorage.getSerializedObservable)
|
|
7
|
+
* and returns a typed [value, setter] tuple.
|
|
8
|
+
*/
|
|
9
|
+
function useStorageSerializedObservable(obs) {
|
|
10
|
+
const [value, setValue] = (0, react_1.useState)(() => obs.getValue());
|
|
11
|
+
(0, react_1.useEffect)(() => {
|
|
12
|
+
const subscription = obs.subscribe((v) => setValue(v));
|
|
13
|
+
return () => subscription.unsubscribe();
|
|
14
|
+
}, [obs]);
|
|
15
|
+
return [value, (v) => obs.next(v)];
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=useStorageSerializedObservable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStorageSerializedObservable.js","sourceRoot":"","sources":["../../src/useStorageSerializedObservable.ts"],"names":[],"mappings":";;AAOA,wEAWC;AAjBD,iCAA4C;AAE5C;;;GAGG;AACH,SAAgB,8BAA8B,CAC5C,GAAoC;IAEpC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAW,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IAEnE,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,YAAY,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;IAC1C,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAEV,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,kCAAkC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,kCAAkC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { StorageObservable } from "@efficimo/storage";
|
|
2
|
+
/**
|
|
3
|
+
* Subscribes to a StorageObservable and returns a [value, setter] tuple,
|
|
4
|
+
* re-rendering the component whenever the storage value changes.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useStorageObservable<K extends string>(obs: StorageObservable<K>): [string | null, (value: string | null) => void];
|
|
7
|
+
//# sourceMappingURL=useStorageObservable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStorageObservable.d.ts","sourceRoot":"","sources":["../../src/useStorageObservable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG3D;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EACnD,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACxB,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC,CASjD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Subscribes to a StorageObservable and returns a [value, setter] tuple,
|
|
4
|
+
* re-rendering the component whenever the storage value changes.
|
|
5
|
+
*/
|
|
6
|
+
export function useStorageObservable(obs) {
|
|
7
|
+
const [value, setValue] = useState(() => obs.getValue());
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const subscription = obs.subscribe((v) => setValue(v));
|
|
10
|
+
return () => subscription.unsubscribe();
|
|
11
|
+
}, [obs]);
|
|
12
|
+
return [value, (v) => obs.next(v)];
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=useStorageObservable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStorageObservable.js","sourceRoot":"","sources":["../../src/useStorageObservable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,GAAyB;IAEzB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IAExE,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,YAAY,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;IAC1C,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAEV,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { JsonSerializeObservableValue } from "@efficimo/observable";
|
|
2
|
+
/**
|
|
3
|
+
* Subscribes to a JsonSerializeObservableValue (from BaseStorage.getSerializedObservable)
|
|
4
|
+
* and returns a typed [value, setter] tuple.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useStorageSerializedObservable<T>(obs: JsonSerializeObservableValue<T>): [T | null, (value: T | null) => void];
|
|
7
|
+
//# sourceMappingURL=useStorageSerializedObservable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStorageSerializedObservable.d.ts","sourceRoot":"","sources":["../../src/useStorageSerializedObservable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAGzE;;;GAGG;AACH,wBAAgB,8BAA8B,CAAC,CAAC,EAC9C,GAAG,EAAE,4BAA4B,CAAC,CAAC,CAAC,GACnC,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC,CASvC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Subscribes to a JsonSerializeObservableValue (from BaseStorage.getSerializedObservable)
|
|
4
|
+
* and returns a typed [value, setter] tuple.
|
|
5
|
+
*/
|
|
6
|
+
export function useStorageSerializedObservable(obs) {
|
|
7
|
+
const [value, setValue] = useState(() => obs.getValue());
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const subscription = obs.subscribe((v) => setValue(v));
|
|
10
|
+
return () => subscription.unsubscribe();
|
|
11
|
+
}, [obs]);
|
|
12
|
+
return [value, (v) => obs.next(v)];
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=useStorageSerializedObservable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStorageSerializedObservable.js","sourceRoot":"","sources":["../../src/useStorageSerializedObservable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C;;;GAGG;AACH,MAAM,UAAU,8BAA8B,CAC5C,GAAoC;IAEpC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAW,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IAEnE,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,YAAY,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;IAC1C,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAEV,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@efficimo/storage-react",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "React bindings for @efficimo/storage: hooks for localStorage and sessionStorage observables.",
|
|
5
|
+
"author": "efficimo",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"storage",
|
|
9
|
+
"localstorage",
|
|
10
|
+
"sessionstorage",
|
|
11
|
+
"observable",
|
|
12
|
+
"react",
|
|
13
|
+
"hooks",
|
|
14
|
+
"typescript"
|
|
15
|
+
],
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/efficimo/storage.git"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/efficimo/storage/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/efficimo/storage#readme",
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/cjs/index.js",
|
|
28
|
+
"module": "./dist/esm/index.js",
|
|
29
|
+
"types": "./dist/esm/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/esm/index.d.ts",
|
|
34
|
+
"default": "./dist/esm/index.js"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/cjs/index.d.ts",
|
|
38
|
+
"default": "./dist/cjs/index.js"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist"
|
|
44
|
+
],
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"registry": "https://registry.npmjs.org",
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && node scripts/postbuild.mjs",
|
|
51
|
+
"typecheck": "tsc --noEmit",
|
|
52
|
+
"prepublishOnly": "npm run build && npm run typecheck"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@efficimo/observable": ">=0.1.0",
|
|
56
|
+
"@efficimo/storage": ">=0.1.0",
|
|
57
|
+
"react": ">=18.0.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@efficimo/observable": "*",
|
|
61
|
+
"@efficimo/storage": "file:../core",
|
|
62
|
+
"@types/node": "^25.0.0",
|
|
63
|
+
"@types/react": "^18.0.0",
|
|
64
|
+
"react": "^18.0.0",
|
|
65
|
+
"typescript": "^5.0.0"
|
|
66
|
+
}
|
|
67
|
+
}
|