@kamod-ch/signals 1.0.0 → 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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +147 -0
  3. 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 ADDED
@@ -0,0 +1,147 @@
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
+
19
+ # @kamod-ch/signals
20
+
21
+ Persisted Preact signals for `localStorage`, `sessionStorage`, IndexedDB, cookies, and memory.
22
+
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.
24
+
25
+ ## Keywords
26
+
27
+ `preact` · `signals` · `preact-signals` · `state-management` · `persistent-state` · `localstorage` · `sessionstorage` · `reactivity` · `typescript` · `vite` · `kamod`
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ npm install @kamod-ch/signals @preact/signals preact
33
+ ```
34
+
35
+ `@preact/signals` and `preact` are peer dependencies.
36
+
37
+ ## Usage
38
+
39
+ ### Basic persisted signal
40
+
41
+ ```ts
42
+ import { persistedSignal } from "@kamod-ch/signals";
43
+
44
+ export const theme = persistedSignal("theme", "dark", { storage: "local" });
45
+ ```
46
+
47
+ ### Preact hook
48
+
49
+ ```tsx
50
+ import { usePersistedSignal } from "@kamod-ch/signals";
51
+
52
+ export function Sidebar() {
53
+ const isOpen = usePersistedSignal("sidebar-open", true, { storage: "session" });
54
+
55
+ return <button onClick={() => (isOpen.value = !isOpen.value)}>Toggle</button>;
56
+ }
57
+ ```
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
+
70
+ ## API
71
+
72
+ ```ts
73
+ persistedSignal<T>(key: string, initialValue: T, options?: PersistedSignalOptions<T>): PersistedSignal<T>
74
+ usePersistedSignal<T>(key: string, initialValue: T, options?: PersistedSignalOptions<T>): PersistedSignal<T>
75
+ ```
76
+
77
+ ```ts
78
+ type PersistedSignalOptions<T> = {
79
+ storage?: "local" | "session" | "indexeddb" | "cookie" | "memory";
80
+ serialize?: (value: T) => string;
81
+ deserialize?: (raw: string) => T;
82
+ sync?: boolean;
83
+ removeOnUndefined?: boolean;
84
+ indexedDB?: { database?: string; store?: string; version?: number };
85
+ cookie?: {
86
+ expires?: number | Date;
87
+ path?: string;
88
+ domain?: string;
89
+ secure?: boolean;
90
+ sameSite?: "Lax" | "Strict" | "None";
91
+ };
92
+ cookieContext?: CookieContext;
93
+ };
94
+ ```
95
+
96
+ All persisted signals keep the normal signal shape, so values are read and written via `.value`.
97
+
98
+ ## SSR cookie context
99
+
100
+ Use `createCookieContext()` when a cookie-backed value must be available during server-side rendering.
101
+
102
+ ```ts
103
+ import { createCookieContext, persistedSignal } from "@kamod-ch/signals";
104
+
105
+ const cookieContext = createCookieContext({
106
+ cookie: request.headers,
107
+ onSetCookie: (header) => response.headers.append("set-cookie", header),
108
+ });
109
+
110
+ const theme = persistedSignal("theme", "dark", {
111
+ storage: "cookie",
112
+ cookieContext,
113
+ cookie: { path: "/", sameSite: "Lax" },
114
+ });
115
+ ```
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
+
125
+ ## Notes
126
+
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.
129
+ - `local`, `session`, and `indexeddb` fall back to in-memory storage when unavailable.
130
+ - IndexedDB hydration is async, so signals start with `initialValue` and update after the persisted value loads.
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.
133
+
134
+ ## Publishing
135
+
136
+ This package is published from `packages/core` only:
137
+
138
+ ```bash
139
+ pnpm publish:core
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.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/kamod-signals.git",
23
+ "url": "git+https://github.com/kamod-ch/signals.git",
11
24
  "directory": "packages/core"
12
25
  },
13
26
  "publishConfig": {