@kamod-ch/signals 1.0.2 → 1.0.3
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/LICENSE +21 -0
- package/README.md +67 -23
- package/package.json +15 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Klaus Zahiragic, Kamod GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,52 +1,77 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/kamod-ch/signals/main/assets/readme-banner.svg" alt="Kamod Signals" width="304" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://www.npmjs.com/package/@kamod-ch/signals"><img src="https://img.shields.io/npm/v/%40kamod-ch%2Fsignals" alt="npm version" /></a>
|
|
7
|
+
<a href="https://github.com/kamod-ch/kamod-signals/actions/workflows/gh-pages.yml"><img src="https://github.com/kamod-ch/kamod-signals/actions/workflows/gh-pages.yml/badge.svg" alt="Docs deploy" /></a>
|
|
8
|
+
<a href="https://github.com/kamod-ch/signals/stargazers"><img src="https://img.shields.io/github/stars/kamod-ch/signals?style=social" alt="GitHub stars" /></a>
|
|
9
|
+
<a href="https://github.com/kamod-ch/signals/blob/main/packages/core/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT license" /></a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
<p align="center">
|
|
13
|
+
<strong><a href="https://kamod-ch.github.io/kamod-signals/">Docs</a></strong> ·
|
|
14
|
+
<strong><a href="https://www.npmjs.com/package/@kamod-ch/signals">npm</a></strong> ·
|
|
15
|
+
<strong><a href="https://github.com/kamod-ch/signals">GitHub</a></strong> ·
|
|
16
|
+
<strong><a href="https://github.com/kamod-ch/signals/issues">Issues</a></strong>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
1
19
|
# @kamod-ch/signals
|
|
2
20
|
|
|
3
21
|
Persisted Preact signals for `localStorage`, `sessionStorage`, IndexedDB, cookies, and memory.
|
|
4
22
|
|
|
5
23
|
`@kamod-ch/signals` is a lightweight helper package for Preact apps that need reactive state with durable storage. It is SSR-safe, supports cookie request contexts, and keeps the familiar `@preact/signals` API.
|
|
6
24
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
25
|
+
## Keywords
|
|
26
|
+
|
|
27
|
+
`preact` · `signals` · `preact-signals` · `state-management` · `persistent-state` · `localstorage` · `sessionstorage` · `reactivity` · `typescript` · `vite` · `kamod`
|
|
10
28
|
|
|
11
|
-
##
|
|
29
|
+
## Installation
|
|
12
30
|
|
|
13
31
|
```bash
|
|
14
|
-
|
|
32
|
+
npm install @kamod-ch/signals @preact/signals preact
|
|
15
33
|
```
|
|
16
34
|
|
|
35
|
+
`@preact/signals` and `preact` are peer dependencies.
|
|
36
|
+
|
|
17
37
|
## Usage
|
|
18
38
|
|
|
39
|
+
### Basic persisted signal
|
|
40
|
+
|
|
19
41
|
```ts
|
|
20
|
-
import { persistedSignal
|
|
42
|
+
import { persistedSignal } from "@kamod-ch/signals";
|
|
21
43
|
|
|
22
44
|
export const theme = persistedSignal("theme", "dark", { storage: "local" });
|
|
45
|
+
```
|
|
23
46
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
47
|
+
### Preact hook
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { usePersistedSignal } from "@kamod-ch/signals";
|
|
28
51
|
|
|
29
|
-
function Sidebar() {
|
|
52
|
+
export function Sidebar() {
|
|
30
53
|
const isOpen = usePersistedSignal("sidebar-open", true, { storage: "session" });
|
|
31
54
|
|
|
32
55
|
return <button onClick={() => (isOpen.value = !isOpen.value)}>Toggle</button>;
|
|
33
56
|
}
|
|
34
57
|
```
|
|
35
58
|
|
|
59
|
+
### Cookie-backed signal
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { persistedSignal } from "@kamod-ch/signals";
|
|
63
|
+
|
|
64
|
+
export const token = persistedSignal("token", "", {
|
|
65
|
+
storage: "cookie",
|
|
66
|
+
cookie: { expires: 7, path: "/" },
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
36
70
|
## API
|
|
37
71
|
|
|
38
72
|
```ts
|
|
39
|
-
persistedSignal<T>(
|
|
40
|
-
|
|
41
|
-
initialValue: T,
|
|
42
|
-
options?: PersistedSignalOptions<T>
|
|
43
|
-
): PersistedSignal<T>;
|
|
44
|
-
|
|
45
|
-
usePersistedSignal<T>(
|
|
46
|
-
key: string,
|
|
47
|
-
initialValue: T,
|
|
48
|
-
options?: PersistedSignalOptions<T>
|
|
49
|
-
): PersistedSignal<T>;
|
|
73
|
+
persistedSignal<T>(key: string, initialValue: T, options?: PersistedSignalOptions<T>): PersistedSignal<T>
|
|
74
|
+
usePersistedSignal<T>(key: string, initialValue: T, options?: PersistedSignalOptions<T>): PersistedSignal<T>
|
|
50
75
|
```
|
|
51
76
|
|
|
52
77
|
```ts
|
|
@@ -68,6 +93,8 @@ type PersistedSignalOptions<T> = {
|
|
|
68
93
|
};
|
|
69
94
|
```
|
|
70
95
|
|
|
96
|
+
All persisted signals keep the normal signal shape, so values are read and written via `.value`.
|
|
97
|
+
|
|
71
98
|
## SSR cookie context
|
|
72
99
|
|
|
73
100
|
Use `createCookieContext()` when a cookie-backed value must be available during server-side rendering.
|
|
@@ -87,12 +114,22 @@ const theme = persistedSignal("theme", "dark", {
|
|
|
87
114
|
});
|
|
88
115
|
```
|
|
89
116
|
|
|
117
|
+
## Storage drivers
|
|
118
|
+
|
|
119
|
+
- `local`: persists to `localStorage` in the browser.
|
|
120
|
+
- `session`: persists to `sessionStorage` in the browser.
|
|
121
|
+
- `indexeddb`: persists asynchronously to IndexedDB.
|
|
122
|
+
- `cookie`: persists to browser cookies or an SSR `cookieContext`.
|
|
123
|
+
- `memory`: keeps values in memory only.
|
|
124
|
+
|
|
90
125
|
## Notes
|
|
91
126
|
|
|
92
127
|
- SSR-safe: browser-only storage is never touched on the server.
|
|
128
|
+
- Cookie SSR works when you pass `cookieContext`, and caching stays scoped to that request context.
|
|
93
129
|
- `local`, `session`, and `indexeddb` fall back to in-memory storage when unavailable.
|
|
94
130
|
- IndexedDB hydration is async, so signals start with `initialValue` and update after the persisted value loads.
|
|
95
|
-
-
|
|
131
|
+
- `persistedSignal()` returns the same signal for the same global identity (`storage + key`, with `cookieContext` scoping for SSR cookies).
|
|
132
|
+
- Reusing that identity requires the same effective options; conflicting options throw instead of being ignored.
|
|
96
133
|
|
|
97
134
|
## Publishing
|
|
98
135
|
|
|
@@ -101,3 +138,10 @@ This package is published from `packages/core` only:
|
|
|
101
138
|
```bash
|
|
102
139
|
pnpm publish:core
|
|
103
140
|
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
Built by Klaus Zahiragic | Kamod GmbH
|
|
145
|
+
|
|
146
|
+
[Website](https://www.kamod.ch) ·
|
|
147
|
+
[LinkedIn](https://www.linkedin.com/in/klauszahiragic/)
|
package/package.json
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kamod-ch/signals",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Persisted Preact signals with localStorage, sessionStorage, IndexedDB, cookie, and memory drivers.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"preact",
|
|
7
|
+
"signals",
|
|
8
|
+
"preact-signals",
|
|
9
|
+
"state-management",
|
|
10
|
+
"persistent-state",
|
|
11
|
+
"localstorage",
|
|
12
|
+
"sessionstorage",
|
|
13
|
+
"reactivity",
|
|
14
|
+
"typescript",
|
|
15
|
+
"vite",
|
|
16
|
+
"kamod"
|
|
17
|
+
],
|
|
5
18
|
"type": "module",
|
|
6
19
|
"license": "MIT",
|
|
7
20
|
"author": "Klaus Zahiragic <watzak>",
|
|
8
21
|
"repository": {
|
|
9
22
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/kamod-ch/
|
|
23
|
+
"url": "git+https://github.com/kamod-ch/signals.git",
|
|
11
24
|
"directory": "packages/core"
|
|
12
25
|
},
|
|
13
26
|
"publishConfig": {
|