gjendje 0.9.0 → 0.9.2
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 +6 -6
- package/dist/{chunk-T665XTGR.cjs → chunk-XACGL7LY.cjs} +0 -3
- package/dist/{chunk-F43ER2S7.js → chunk-ZCZG3Y2B.js} +0 -3
- package/dist/index.cjs +20 -20
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/server.cjs +4 -4
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/{types-DTQEK0tB.d.cts → types-D-VJhL7I.d.cts} +0 -5
- package/dist/{types-DTQEK0tB.d.ts → types-D-VJhL7I.d.ts} +0 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,14 +25,14 @@ const theme = state.local({ theme: 'light' })
|
|
|
25
25
|
For in-memory state that doesn't persist, use `state` without a scope:
|
|
26
26
|
|
|
27
27
|
```ts
|
|
28
|
-
const
|
|
28
|
+
const filters = state({ role: 'all', status: 'active', tags: [] })
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
### Getting values
|
|
32
32
|
|
|
33
33
|
```ts
|
|
34
|
-
const
|
|
35
|
-
const
|
|
34
|
+
const filters = store.get() // Returns the full state object
|
|
35
|
+
const { role, status } = store.get() // Get values by destructuring
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
### Updating values
|
|
@@ -49,8 +49,8 @@ For object stores, `patch` lets you update specific properties without spreading
|
|
|
49
49
|
```ts
|
|
50
50
|
const form = state({ name: '', email: '', age: 0 })
|
|
51
51
|
|
|
52
|
-
form.patch({ name: 'Alice' }) //
|
|
53
|
-
form.patch({ name: 'Bob', age: 30 }) //
|
|
52
|
+
form.patch({ name: 'Alice' }) // Only updates name
|
|
53
|
+
form.patch({ name: 'Bob', age: 30 }) // Update multiple properties at once
|
|
54
54
|
```
|
|
55
55
|
|
|
56
56
|
[More examples](https://github.com/charliebeckstrand/gjendje/blob/main/docs/examples.md)
|
|
@@ -100,7 +100,7 @@ configure({
|
|
|
100
100
|
|
|
101
101
|
## API
|
|
102
102
|
|
|
103
|
-
Every scope shares the same core API: `get`, `
|
|
103
|
+
Every scope shares the same core API: `get`, `set`, `patch`, `reset`, `subscribe`, `watch`, `intercept`, `use`, `destroy`
|
|
104
104
|
|
|
105
105
|
[API reference guide](https://github.com/charliebeckstrand/gjendje/blob/main/docs/api.md)
|
|
106
106
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkXACGL7LY_cjs = require('./chunk-XACGL7LY.cjs');
|
|
4
4
|
|
|
5
5
|
// src/collection.ts
|
|
6
6
|
function collection(key, options) {
|
|
7
|
-
const base =
|
|
7
|
+
const base = chunkXACGL7LY_cjs.createBase(key, options);
|
|
8
8
|
const watchers = /* @__PURE__ */ new Map();
|
|
9
9
|
let prevItems = base.get();
|
|
10
10
|
const unsubscribe = base.subscribe((next) => {
|
|
@@ -139,7 +139,7 @@ function collection(key, options) {
|
|
|
139
139
|
// src/computed.ts
|
|
140
140
|
var computedCounter = 0;
|
|
141
141
|
function computed(deps, fn, options) {
|
|
142
|
-
const listeners =
|
|
142
|
+
const listeners = chunkXACGL7LY_cjs.createListeners();
|
|
143
143
|
const instanceKey = options?.key ?? `computed:${computedCounter++}`;
|
|
144
144
|
let cached;
|
|
145
145
|
let isDirty = true;
|
|
@@ -164,7 +164,7 @@ function computed(deps, fn, options) {
|
|
|
164
164
|
};
|
|
165
165
|
const markDirty = () => {
|
|
166
166
|
isDirty = true;
|
|
167
|
-
|
|
167
|
+
chunkXACGL7LY_cjs.notify(notifyListeners);
|
|
168
168
|
};
|
|
169
169
|
const unsubscribers = new Array(depLen);
|
|
170
170
|
for (let i = 0; i < depLen; i++) {
|
|
@@ -224,7 +224,7 @@ function computed(deps, fn, options) {
|
|
|
224
224
|
|
|
225
225
|
// src/devtools.ts
|
|
226
226
|
function snapshot() {
|
|
227
|
-
const registry =
|
|
227
|
+
const registry = chunkXACGL7LY_cjs.getRegistry();
|
|
228
228
|
const result = [];
|
|
229
229
|
for (const instance of registry.values()) {
|
|
230
230
|
result.push({
|
|
@@ -407,7 +407,7 @@ function withWatch(instance) {
|
|
|
407
407
|
// src/previous.ts
|
|
408
408
|
var previousCounter = 0;
|
|
409
409
|
function previous(source, options) {
|
|
410
|
-
const listeners =
|
|
410
|
+
const listeners = chunkXACGL7LY_cjs.createListeners();
|
|
411
411
|
const instanceKey = options?.key ?? `previous:${previousCounter++}`;
|
|
412
412
|
let prev;
|
|
413
413
|
let current = source.get();
|
|
@@ -417,7 +417,7 @@ function previous(source, options) {
|
|
|
417
417
|
prev = current;
|
|
418
418
|
current = next;
|
|
419
419
|
if (old !== prev) {
|
|
420
|
-
|
|
420
|
+
chunkXACGL7LY_cjs.notify(() => listeners.notify(prev));
|
|
421
421
|
}
|
|
422
422
|
});
|
|
423
423
|
let destroyedPromise;
|
|
@@ -479,7 +479,7 @@ function readonly(instance) {
|
|
|
479
479
|
// src/select.ts
|
|
480
480
|
var selectCounter = 0;
|
|
481
481
|
function select(source, fn, options) {
|
|
482
|
-
const listeners =
|
|
482
|
+
const listeners = chunkXACGL7LY_cjs.createListeners();
|
|
483
483
|
const instanceKey = options?.key ?? `select:${selectCounter++}`;
|
|
484
484
|
let cached;
|
|
485
485
|
let isDirty = true;
|
|
@@ -498,7 +498,7 @@ function select(source, fn, options) {
|
|
|
498
498
|
};
|
|
499
499
|
const markDirty = () => {
|
|
500
500
|
isDirty = true;
|
|
501
|
-
|
|
501
|
+
chunkXACGL7LY_cjs.notify(notifyListeners);
|
|
502
502
|
};
|
|
503
503
|
const unsubscribe = source.subscribe(markDirty);
|
|
504
504
|
recompute();
|
|
@@ -553,7 +553,7 @@ function createState(key, options) {
|
|
|
553
553
|
if (!key) {
|
|
554
554
|
throw new Error("[state] key must be a non-empty string.");
|
|
555
555
|
}
|
|
556
|
-
const config =
|
|
556
|
+
const config = chunkXACGL7LY_cjs.getConfig();
|
|
557
557
|
if (config.keyPattern && !config.keyPattern.test(key)) {
|
|
558
558
|
throw new Error(
|
|
559
559
|
`[gjendje] Key "${key}" does not match the configured keyPattern ${config.keyPattern}.`
|
|
@@ -561,26 +561,26 @@ function createState(key, options) {
|
|
|
561
561
|
}
|
|
562
562
|
const rawScope = options.scope ?? config.scope ?? "render";
|
|
563
563
|
const scope = rawScope === "memory" ? "render" : rawScope === "session" ? "tab" : rawScope;
|
|
564
|
-
const rKey =
|
|
565
|
-
const existing =
|
|
564
|
+
const rKey = chunkXACGL7LY_cjs.scopedKey(key, scope);
|
|
565
|
+
const existing = chunkXACGL7LY_cjs.getRegistered(rKey);
|
|
566
566
|
if (existing && !existing.isDestroyed) {
|
|
567
567
|
if (config.warnOnDuplicate) {
|
|
568
|
-
|
|
568
|
+
chunkXACGL7LY_cjs.log("warn", `Duplicate state("${key}") with scope "${scope}". Returning cached instance.`);
|
|
569
569
|
}
|
|
570
570
|
return existing;
|
|
571
571
|
}
|
|
572
572
|
if (scope === "render" && !options.ssr && !config.ssr) {
|
|
573
573
|
if (options.sync) {
|
|
574
|
-
|
|
574
|
+
chunkXACGL7LY_cjs.log(
|
|
575
575
|
"warn",
|
|
576
576
|
`sync: true is ignored for scope "render". Only "local" and "bucket" scopes support cross-tab sync.`
|
|
577
577
|
);
|
|
578
578
|
}
|
|
579
|
-
const instance =
|
|
580
|
-
|
|
579
|
+
const instance = chunkXACGL7LY_cjs.createRenderState(key, rKey, options, config);
|
|
580
|
+
chunkXACGL7LY_cjs.registerByKey(rKey, key, scope, instance, config);
|
|
581
581
|
return instance;
|
|
582
582
|
}
|
|
583
|
-
return
|
|
583
|
+
return chunkXACGL7LY_cjs.createBase(key, options);
|
|
584
584
|
}
|
|
585
585
|
|
|
586
586
|
// src/shortcuts.ts
|
|
@@ -664,15 +664,15 @@ function bucket(entry, options) {
|
|
|
664
664
|
|
|
665
665
|
Object.defineProperty(exports, "batch", {
|
|
666
666
|
enumerable: true,
|
|
667
|
-
get: function () { return
|
|
667
|
+
get: function () { return chunkXACGL7LY_cjs.batch; }
|
|
668
668
|
});
|
|
669
669
|
Object.defineProperty(exports, "configure", {
|
|
670
670
|
enumerable: true,
|
|
671
|
-
get: function () { return
|
|
671
|
+
get: function () { return chunkXACGL7LY_cjs.configure; }
|
|
672
672
|
});
|
|
673
673
|
Object.defineProperty(exports, "shallowEqual", {
|
|
674
674
|
enumerable: true,
|
|
675
|
-
get: function () { return
|
|
675
|
+
get: function () { return chunkXACGL7LY_cjs.shallowEqual; }
|
|
676
676
|
});
|
|
677
677
|
exports.bucket = bucket;
|
|
678
678
|
exports.collection = collection;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as BaseInstance, U as Unsubscribe, S as StateOptions, R as ReadonlyInstance, a as Scope, b as StateInstance } from './types-
|
|
2
|
-
export { A as Adapter, c as BucketOptions, E as Enhancer, L as Listener, d as Serializer } from './types-
|
|
1
|
+
import { B as BaseInstance, U as Unsubscribe, S as StateOptions, R as ReadonlyInstance, a as Scope, b as StateInstance } from './types-D-VJhL7I.cjs';
|
|
2
|
+
export { A as Adapter, c as BucketOptions, E as Enhancer, L as Listener, d as Serializer } from './types-D-VJhL7I.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Runs all state updates inside fn as a single batch.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as BaseInstance, U as Unsubscribe, S as StateOptions, R as ReadonlyInstance, a as Scope, b as StateInstance } from './types-
|
|
2
|
-
export { A as Adapter, c as BucketOptions, E as Enhancer, L as Listener, d as Serializer } from './types-
|
|
1
|
+
import { B as BaseInstance, U as Unsubscribe, S as StateOptions, R as ReadonlyInstance, a as Scope, b as StateInstance } from './types-D-VJhL7I.js';
|
|
2
|
+
export { A as Adapter, c as BucketOptions, E as Enhancer, L as Listener, d as Serializer } from './types-D-VJhL7I.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Runs all state updates inside fn as a single batch.
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createBase, createListeners, getRegistry, notify, getConfig, scopedKey, getRegistered, log, createRenderState, registerByKey } from './chunk-
|
|
2
|
-
export { batch, configure, shallowEqual } from './chunk-
|
|
1
|
+
import { createBase, createListeners, getRegistry, notify, getConfig, scopedKey, getRegistered, log, createRenderState, registerByKey } from './chunk-ZCZG3Y2B.js';
|
|
2
|
+
export { batch, configure, shallowEqual } from './chunk-ZCZG3Y2B.js';
|
|
3
3
|
|
|
4
4
|
// src/collection.ts
|
|
5
5
|
function collection(key, options) {
|
package/dist/server.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkXACGL7LY_cjs = require('./chunk-XACGL7LY.cjs');
|
|
4
4
|
var async_hooks = require('async_hooks');
|
|
5
5
|
|
|
6
6
|
var als = new async_hooks.AsyncLocalStorage();
|
|
@@ -9,7 +9,7 @@ async function withServerSession(fn) {
|
|
|
9
9
|
return als.run(store, fn);
|
|
10
10
|
}
|
|
11
11
|
function createServerAdapter(key, defaultValue) {
|
|
12
|
-
const listeners =
|
|
12
|
+
const listeners = chunkXACGL7LY_cjs.createListeners();
|
|
13
13
|
function getStore() {
|
|
14
14
|
return als.getStore();
|
|
15
15
|
}
|
|
@@ -31,7 +31,7 @@ function createServerAdapter(key, defaultValue) {
|
|
|
31
31
|
}
|
|
32
32
|
store.set(key, value);
|
|
33
33
|
lastNotifiedValue = value;
|
|
34
|
-
|
|
34
|
+
chunkXACGL7LY_cjs.notify(notifyListeners);
|
|
35
35
|
},
|
|
36
36
|
subscribe: listeners.subscribe,
|
|
37
37
|
destroy() {
|
|
@@ -39,7 +39,7 @@ function createServerAdapter(key, defaultValue) {
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
chunkXACGL7LY_cjs.registerServerAdapter(createServerAdapter);
|
|
43
43
|
|
|
44
44
|
exports.createServerAdapter = createServerAdapter;
|
|
45
45
|
exports.withServerSession = withServerSession;
|
package/dist/server.d.cts
CHANGED
package/dist/server.d.ts
CHANGED
package/dist/server.js
CHANGED
|
@@ -69,11 +69,6 @@ interface StateInstance<T> extends BaseInstance<T> {
|
|
|
69
69
|
* Listener only fires when that key's value changes.
|
|
70
70
|
*/
|
|
71
71
|
watch<K extends T extends object ? keyof T : never>(key: K, listener: (value: T[K & keyof T]) => void): Unsubscribe;
|
|
72
|
-
/**
|
|
73
|
-
* Read a single property from the current object value.
|
|
74
|
-
* Only available when T is an object type.
|
|
75
|
-
*/
|
|
76
|
-
pick<K extends T extends object ? keyof T : never>(key: K): T[K & keyof T];
|
|
77
72
|
/**
|
|
78
73
|
* Merge a partial update into the current object value (shallow merge).
|
|
79
74
|
* Only available when T is an object type.
|
|
@@ -69,11 +69,6 @@ interface StateInstance<T> extends BaseInstance<T> {
|
|
|
69
69
|
* Listener only fires when that key's value changes.
|
|
70
70
|
*/
|
|
71
71
|
watch<K extends T extends object ? keyof T : never>(key: K, listener: (value: T[K & keyof T]) => void): Unsubscribe;
|
|
72
|
-
/**
|
|
73
|
-
* Read a single property from the current object value.
|
|
74
|
-
* Only available when T is an object type.
|
|
75
|
-
*/
|
|
76
|
-
pick<K extends T extends object ? keyof T : never>(key: K): T[K & keyof T];
|
|
77
72
|
/**
|
|
78
73
|
* Merge a partial update into the current object value (shallow merge).
|
|
79
74
|
* Only available when T is an object type.
|