gjendje 0.3.2 → 0.3.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/README.md +23 -76
- package/dist/index.cjs +1437 -38
- package/dist/index.d.cts +395 -4
- package/dist/index.d.ts +395 -4
- package/dist/index.js +1427 -3
- package/package.json +10 -29
- package/dist/chunk-7C4HRTL3.js +0 -1127
- package/dist/chunk-7C4HRTL3.js.map +0 -1
- package/dist/chunk-FKGUEXPG.cjs +0 -1136
- package/dist/chunk-FKGUEXPG.cjs.map +0 -1
- package/dist/factory-CIj-6WlO.d.cts +0 -316
- package/dist/factory-CIj-6WlO.d.ts +0 -316
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/react/index.cjs +0 -150
- package/dist/react/index.cjs.map +0 -1
- package/dist/react/index.d.cts +0 -16
- package/dist/react/index.d.ts +0 -16
- package/dist/react/index.js +0 -117
- package/dist/react/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,117 +2,68 @@
|
|
|
2
2
|
|
|
3
3
|
# gjendje
|
|
4
4
|
|
|
5
|
-
**gjendje** unifies state management across
|
|
5
|
+
**gjendje** unifies state management across storage backends.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import { state } from 'gjendje'
|
|
12
|
-
|
|
13
|
-
const theme = state('theme', {
|
|
14
|
-
default: 'light',
|
|
15
|
-
scope: 'local',
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
theme.get()
|
|
9
|
+
```sh
|
|
10
|
+
npm install gjendje
|
|
19
11
|
```
|
|
20
12
|
|
|
21
|
-
|
|
22
|
-
```ts
|
|
23
|
-
import { state } from 'gjendje'
|
|
24
|
-
|
|
25
|
-
const settings = state('settings', {
|
|
26
|
-
default: { notifications: true, theme: 'light' },
|
|
27
|
-
scope: 'bucket',
|
|
28
|
-
bucket: {
|
|
29
|
-
name: 'app-settings',
|
|
30
|
-
},
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
await settings.ready
|
|
13
|
+
## Configure
|
|
34
14
|
|
|
35
|
-
|
|
36
|
-
```
|
|
15
|
+
Sets global defaults for all state instances.
|
|
37
16
|
|
|
38
|
-
|
|
17
|
+
Call once at your app entry point.
|
|
39
18
|
|
|
40
19
|
```ts
|
|
41
|
-
configure
|
|
42
|
-
```
|
|
20
|
+
import { configure } from 'gjendje'
|
|
43
21
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
#### Settings
|
|
22
|
+
configure({ scope: 'local' })
|
|
23
|
+
```
|
|
47
24
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
- `logLevel` — `'warn'`
|
|
51
|
-
- `maxKeys`
|
|
52
|
-
- `prefix`
|
|
53
|
-
- `requireValidation`
|
|
54
|
-
- `ssr`
|
|
55
|
-
- `sync`
|
|
56
|
-
- `warnOnDuplicate`
|
|
25
|
+
```ts
|
|
26
|
+
import { state } from 'gjendje'
|
|
57
27
|
|
|
58
|
-
|
|
28
|
+
const theme = state('theme', { default: 'light' })
|
|
59
29
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
- `onHydrate`
|
|
63
|
-
- `onMigrate`
|
|
64
|
-
- `onQuotaExceeded`
|
|
65
|
-
- `onRegister`
|
|
66
|
-
- `onSync`
|
|
30
|
+
theme.scope // 'local' — derived from configure
|
|
31
|
+
```
|
|
67
32
|
|
|
68
|
-
[Full configure reference](https://github.com/charliebeckstrand/gjendje/blob/main/docs/configure.md)
|
|
33
|
+
[Full configure reference](https://github.com/charliebeckstrand/gjendje/blob/main/docs/configure.md)
|
|
69
34
|
|
|
70
35
|
## Scopes
|
|
71
36
|
|
|
72
37
|
|Scope |Description |
|
|
73
38
|
|-----------|--------------------------------------------------------|
|
|
74
39
|
|`render` | `memory` |
|
|
75
|
-
|`local` |`localStorage`
|
|
76
|
-
|`server` |`AsyncLocalStorage`
|
|
77
|
-
|`bucket` | `Storage Buckets` |
|
|
40
|
+
|`local` |`localStorage` |
|
|
41
|
+
|`server` |`AsyncLocalStorage` |
|
|
42
|
+
|`bucket` | `Storage Buckets API ` |
|
|
78
43
|
|`url` |`URLSearchParams` |
|
|
79
44
|
|`tab` |`sessionStorage` |
|
|
80
45
|
|
|
81
46
|
## API
|
|
82
47
|
|
|
83
|
-
Every `state()` instance exposes the same interface regardless of scope.
|
|
84
|
-
|
|
85
48
|
#### `get()`
|
|
86
49
|
Returns the current value. Reactive — triggers tracking in `computed` and `effect`.
|
|
87
50
|
|
|
88
51
|
#### `set(value)` / `set(prev => next)`
|
|
89
52
|
Replaces the current value. Accepts a direct value or an updater function that receives the previous value.
|
|
90
53
|
|
|
54
|
+
#### `intercept(fn)`
|
|
55
|
+
Receives `(next, prev)` before each update. Return the value to store, or return `prev` to reject the change. Returns an `unsubscribe` function.
|
|
56
|
+
|
|
91
57
|
#### `subscribe(fn)`
|
|
92
58
|
Calls `fn` on every change. Returns an `unsubscribe` function.
|
|
93
59
|
|
|
94
60
|
#### `watch(key, fn)`
|
|
95
61
|
Like `subscribe`, but scoped to a single key within an object value. Only fires when that key changes.
|
|
96
62
|
|
|
97
|
-
|
|
98
|
-
Receives `(next, prev)` before each update. Return the value to store, or return `prev` to reject the change. Returns an `unsubscribe` function.
|
|
99
|
-
|
|
100
|
-
[Full API reference](https://github.com/charliebeckstrand/gjendje/blob/main/docs/api.md) — all methods, promise lifecycle, options, and types.
|
|
101
|
-
|
|
102
|
-
## Middleware
|
|
103
|
-
|
|
104
|
-
Primitives that plug into the update pipeline of any state instance.
|
|
105
|
-
|
|
106
|
-
#### `intercept(fn)`
|
|
107
|
-
Runs **before** a value is stored. Receives `(next, prev)` and returns the value to actually persist. Return `prev` to reject the update. Multiple interceptors run in registration order.
|
|
108
|
-
|
|
109
|
-
#### `use(fn)`
|
|
110
|
-
Runs **after** a value is stored. Receives `(next, prev)`. Return value is ignored. Useful for logging, analytics, or syncing external systems.
|
|
63
|
+
[Full API reference](https://github.com/charliebeckstrand/gjendje/blob/main/docs/api.md)
|
|
111
64
|
|
|
112
65
|
## Derived state
|
|
113
66
|
|
|
114
|
-
Primitives that build on top of `state` to handle computed values, collections, and side effects.
|
|
115
|
-
|
|
116
67
|
#### `computed(deps, fn)`
|
|
117
68
|
Derives a reactive, read-only value from one or more state dependencies. Recomputes only when a dependency changes and caches the result between changes. Returns a `ReadonlyInstance` — no `set()` or `reset()`.
|
|
118
69
|
|
|
@@ -122,10 +73,6 @@ Reactive array with first-class mutation methods — `add`, `remove`, `update`,
|
|
|
122
73
|
#### `effect(deps, fn)`
|
|
123
74
|
Runs a side effect immediately and re-runs whenever any dependency changes. The callback can return a cleanup function that runs before the next execution and on `stop()`. Returns an `EffectHandle` with a `stop()` method.
|
|
124
75
|
|
|
125
|
-
## React
|
|
126
|
-
|
|
127
|
-
[Full React API reference](https://github.com/charliebeckstrand/gjendje/blob/main/docs/react.md)
|
|
128
|
-
|
|
129
76
|
## License
|
|
130
77
|
|
|
131
78
|
MIT
|