gjendje 0.3.2 → 0.3.4

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 CHANGED
@@ -2,117 +2,70 @@
2
2
 
3
3
  # gjendje
4
4
 
5
- **gjendje** unifies state management across any storage backend.
5
+ **gjendje** unifies state management across storage backends.
6
6
 
7
- ## Examples
7
+ ## Install
8
8
 
9
- #### localStorage
10
- ```ts
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
- #### Storage Buckets API
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
- settings.set(prev => ({ ...prev, notifications: false }))
36
- ```
15
+ Sets global defaults for all state instances.
37
16
 
38
- ## Configure
17
+ Call once at your app entry point.
39
18
 
40
19
  ```ts
41
- configure(config: GjendjeConfig): void
42
- ```
20
+ import { configure } from 'gjendje'
43
21
 
44
- Sets global defaults for all state instances. Call once at app startup before creating any state.
22
+ configure({ scope: 'local' })
23
+ ```
45
24
 
46
- #### Settings
25
+ ## Usage
47
26
 
48
- - `defaultScope` — `'render'`
49
- - `keyPattern`
50
- - `logLevel` — `'warn'`
51
- - `maxKeys`
52
- - `prefix`
53
- - `requireValidation`
54
- - `ssr`
55
- - `sync`
56
- - `warnOnDuplicate`
27
+ ```ts
28
+ import { state } from 'gjendje'
57
29
 
58
- #### Lifecycle hooks
30
+ const theme = state('theme', { default: 'light' })
59
31
 
60
- - `onDestroy`
61
- - `onError`
62
- - `onHydrate`
63
- - `onMigrate`
64
- - `onQuotaExceeded`
65
- - `onRegister`
66
- - `onSync`
32
+ theme.scope // 'local' — derived from configure
33
+ ```
67
34
 
68
- [Full configure reference](https://github.com/charliebeckstrand/gjendje/blob/main/docs/configure.md) — all options, validation, error handling, and examples.
35
+ [Full configure reference](https://github.com/charliebeckstrand/gjendje/blob/main/docs/configure.md)
69
36
 
70
37
  ## Scopes
71
38
 
72
39
  |Scope |Description |
73
40
  |-----------|--------------------------------------------------------|
74
41
  |`render` | `memory` |
75
- |`local` |`localStorage` |
76
- |`server` |`AsyncLocalStorage` |
77
- |`bucket` | `Storage Buckets` |
42
+ |`local` |`localStorage` |
43
+ |`server` |`AsyncLocalStorage` |
44
+ |`bucket` | `Storage Buckets API ` |
78
45
  |`url` |`URLSearchParams` |
79
46
  |`tab` |`sessionStorage` |
80
47
 
81
48
  ## API
82
49
 
83
- Every `state()` instance exposes the same interface regardless of scope.
84
-
85
50
  #### `get()`
86
51
  Returns the current value. Reactive — triggers tracking in `computed` and `effect`.
87
52
 
88
53
  #### `set(value)` / `set(prev => next)`
89
54
  Replaces the current value. Accepts a direct value or an updater function that receives the previous value.
90
55
 
56
+ #### `intercept(fn)`
57
+ Receives `(next, prev)` before each update. Return the value to store, or return `prev` to reject the change. Returns an `unsubscribe` function.
58
+
91
59
  #### `subscribe(fn)`
92
60
  Calls `fn` on every change. Returns an `unsubscribe` function.
93
61
 
94
62
  #### `watch(key, fn)`
95
63
  Like `subscribe`, but scoped to a single key within an object value. Only fires when that key changes.
96
64
 
97
- #### `intercept(fn)`
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.
65
+ [Full API reference](https://github.com/charliebeckstrand/gjendje/blob/main/docs/api.md)
111
66
 
112
67
  ## Derived state
113
68
 
114
- Primitives that build on top of `state` to handle computed values, collections, and side effects.
115
-
116
69
  #### `computed(deps, fn)`
117
70
  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
71
 
@@ -122,10 +75,6 @@ Reactive array with first-class mutation methods — `add`, `remove`, `update`,
122
75
  #### `effect(deps, fn)`
123
76
  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
77
 
125
- ## React
126
-
127
- [Full React API reference](https://github.com/charliebeckstrand/gjendje/blob/main/docs/react.md)
128
-
129
78
  ## License
130
79
 
131
80
  MIT