gjendje 0.4.4 → 0.5.0

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.
@@ -703,7 +703,7 @@ var StateImpl = class {
703
703
  lastValue: adapter.get(),
704
704
  isDestroyed: false,
705
705
  interceptors: void 0,
706
- hooks: void 0,
706
+ changeHandlers: void 0,
707
707
  settled: RESOLVED2,
708
708
  resolveDestroyed: void 0,
709
709
  destroyed: void 0,
@@ -733,8 +733,8 @@ var StateImpl = class {
733
733
  s.lastValue = next;
734
734
  this._adapter.set(next);
735
735
  s.settled = this._adapter.ready;
736
- if (s.hooks !== void 0 && s.hooks.size > 0) {
737
- for (const hook of s.hooks) {
736
+ if (s.changeHandlers !== void 0 && s.changeHandlers.size > 0) {
737
+ for (const hook of s.changeHandlers) {
738
738
  hook(next, prev);
739
739
  }
740
740
  }
@@ -756,8 +756,8 @@ var StateImpl = class {
756
756
  s.lastValue = next;
757
757
  this._adapter.set(next);
758
758
  s.settled = this._adapter.ready;
759
- if (s.hooks !== void 0 && s.hooks.size > 0) {
760
- for (const hook of s.hooks) {
759
+ if (s.changeHandlers !== void 0 && s.changeHandlers.size > 0) {
760
+ for (const hook of s.changeHandlers) {
761
761
  hook(next, prev);
762
762
  }
763
763
  }
@@ -791,12 +791,12 @@ var StateImpl = class {
791
791
  s.interceptors?.delete(fn);
792
792
  };
793
793
  }
794
- use(fn) {
794
+ onChange(fn) {
795
795
  const s = this._s;
796
- if (!s.hooks) s.hooks = /* @__PURE__ */ new Set();
797
- s.hooks.add(fn);
796
+ if (!s.changeHandlers) s.changeHandlers = /* @__PURE__ */ new Set();
797
+ s.changeHandlers.add(fn);
798
798
  return () => {
799
- s.hooks?.delete(fn);
799
+ s.changeHandlers?.delete(fn);
800
800
  };
801
801
  }
802
802
  watch(watchKey, listener) {
@@ -823,7 +823,7 @@ var StateImpl = class {
823
823
  s.lastValue = this._adapter.get();
824
824
  s.isDestroyed = true;
825
825
  s.interceptors?.clear();
826
- s.hooks?.clear();
826
+ s.changeHandlers?.clear();
827
827
  s.watchers?.clear();
828
828
  s.watchUnsub?.();
829
829
  this._adapter.destroy?.();
@@ -891,8 +891,8 @@ var RenderStateImpl = class extends StateImpl {
891
891
  if (s.notifyFn !== void 0) {
892
892
  notify(s.notifyFn);
893
893
  }
894
- if (s.hooks !== void 0 && s.hooks.size > 0) {
895
- for (const hook of s.hooks) {
894
+ if (s.changeHandlers !== void 0 && s.changeHandlers.size > 0) {
895
+ for (const hook of s.changeHandlers) {
896
896
  hook(next, prev);
897
897
  }
898
898
  }
@@ -933,8 +933,8 @@ var RenderStateImpl = class extends StateImpl {
933
933
  if (s.notifyFn !== void 0) {
934
934
  notify(s.notifyFn);
935
935
  }
936
- if (s.hooks !== void 0 && s.hooks.size > 0) {
937
- for (const hook of s.hooks) {
936
+ if (s.changeHandlers !== void 0 && s.changeHandlers.size > 0) {
937
+ for (const hook of s.changeHandlers) {
938
938
  hook(next, prev);
939
939
  }
940
940
  }
@@ -969,7 +969,7 @@ var RenderStateImpl = class extends StateImpl {
969
969
  s.lastValue = s.current;
970
970
  s.isDestroyed = true;
971
971
  s.interceptors?.clear();
972
- s.hooks?.clear();
972
+ s.changeHandlers?.clear();
973
973
  s.watchers?.clear();
974
974
  s.watchUnsub?.();
975
975
  s.renderListeners?.clear();
@@ -701,7 +701,7 @@ var StateImpl = class {
701
701
  lastValue: adapter.get(),
702
702
  isDestroyed: false,
703
703
  interceptors: void 0,
704
- hooks: void 0,
704
+ changeHandlers: void 0,
705
705
  settled: RESOLVED2,
706
706
  resolveDestroyed: void 0,
707
707
  destroyed: void 0,
@@ -731,8 +731,8 @@ var StateImpl = class {
731
731
  s.lastValue = next;
732
732
  this._adapter.set(next);
733
733
  s.settled = this._adapter.ready;
734
- if (s.hooks !== void 0 && s.hooks.size > 0) {
735
- for (const hook of s.hooks) {
734
+ if (s.changeHandlers !== void 0 && s.changeHandlers.size > 0) {
735
+ for (const hook of s.changeHandlers) {
736
736
  hook(next, prev);
737
737
  }
738
738
  }
@@ -754,8 +754,8 @@ var StateImpl = class {
754
754
  s.lastValue = next;
755
755
  this._adapter.set(next);
756
756
  s.settled = this._adapter.ready;
757
- if (s.hooks !== void 0 && s.hooks.size > 0) {
758
- for (const hook of s.hooks) {
757
+ if (s.changeHandlers !== void 0 && s.changeHandlers.size > 0) {
758
+ for (const hook of s.changeHandlers) {
759
759
  hook(next, prev);
760
760
  }
761
761
  }
@@ -789,12 +789,12 @@ var StateImpl = class {
789
789
  s.interceptors?.delete(fn);
790
790
  };
791
791
  }
792
- use(fn) {
792
+ onChange(fn) {
793
793
  const s = this._s;
794
- if (!s.hooks) s.hooks = /* @__PURE__ */ new Set();
795
- s.hooks.add(fn);
794
+ if (!s.changeHandlers) s.changeHandlers = /* @__PURE__ */ new Set();
795
+ s.changeHandlers.add(fn);
796
796
  return () => {
797
- s.hooks?.delete(fn);
797
+ s.changeHandlers?.delete(fn);
798
798
  };
799
799
  }
800
800
  watch(watchKey, listener) {
@@ -821,7 +821,7 @@ var StateImpl = class {
821
821
  s.lastValue = this._adapter.get();
822
822
  s.isDestroyed = true;
823
823
  s.interceptors?.clear();
824
- s.hooks?.clear();
824
+ s.changeHandlers?.clear();
825
825
  s.watchers?.clear();
826
826
  s.watchUnsub?.();
827
827
  this._adapter.destroy?.();
@@ -889,8 +889,8 @@ var RenderStateImpl = class extends StateImpl {
889
889
  if (s.notifyFn !== void 0) {
890
890
  notify(s.notifyFn);
891
891
  }
892
- if (s.hooks !== void 0 && s.hooks.size > 0) {
893
- for (const hook of s.hooks) {
892
+ if (s.changeHandlers !== void 0 && s.changeHandlers.size > 0) {
893
+ for (const hook of s.changeHandlers) {
894
894
  hook(next, prev);
895
895
  }
896
896
  }
@@ -931,8 +931,8 @@ var RenderStateImpl = class extends StateImpl {
931
931
  if (s.notifyFn !== void 0) {
932
932
  notify(s.notifyFn);
933
933
  }
934
- if (s.hooks !== void 0 && s.hooks.size > 0) {
935
- for (const hook of s.hooks) {
934
+ if (s.changeHandlers !== void 0 && s.changeHandlers.size > 0) {
935
+ for (const hook of s.changeHandlers) {
936
936
  hook(next, prev);
937
937
  }
938
938
  }
@@ -967,7 +967,7 @@ var RenderStateImpl = class extends StateImpl {
967
967
  s.lastValue = s.current;
968
968
  s.isDestroyed = true;
969
969
  s.interceptors?.clear();
970
- s.hooks?.clear();
970
+ s.changeHandlers?.clear();
971
971
  s.watchers?.clear();
972
972
  s.watchUnsub?.();
973
973
  s.renderListeners?.clear();
package/dist/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunkZQ2PWVTL_cjs = require('./chunk-ZQ2PWVTL.cjs');
3
+ var chunkSCIDKAI5_cjs = require('./chunk-SCIDKAI5.cjs');
4
4
 
5
5
  // src/collection.ts
6
6
  function collection(key, options) {
7
- const base = chunkZQ2PWVTL_cjs.createBase(key, options);
7
+ const base = chunkSCIDKAI5_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 = chunkZQ2PWVTL_cjs.createListeners();
142
+ const listeners = chunkSCIDKAI5_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
- chunkZQ2PWVTL_cjs.notify(notifyListeners);
167
+ chunkSCIDKAI5_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 = chunkZQ2PWVTL_cjs.getRegistry();
227
+ const registry = chunkSCIDKAI5_cjs.getRegistry();
228
228
  const result = [];
229
229
  for (const instance of registry.values()) {
230
230
  result.push({
@@ -410,39 +410,39 @@ function state(key, optionsOrDefault) {
410
410
  if (!key) {
411
411
  throw new Error("[state] key must be a non-empty string.");
412
412
  }
413
- const config = chunkZQ2PWVTL_cjs.getConfig();
413
+ const config = chunkSCIDKAI5_cjs.getConfig();
414
414
  if (config.keyPattern && !config.keyPattern.test(key)) {
415
415
  throw new Error(
416
416
  `[gjendje] Key "${key}" does not match the configured keyPattern ${config.keyPattern}.`
417
417
  );
418
418
  }
419
419
  const scope = options.scope ?? config.scope ?? "render";
420
- const rKey = chunkZQ2PWVTL_cjs.scopedKey(key, scope);
421
- const existing = chunkZQ2PWVTL_cjs.getRegistered(rKey);
420
+ const rKey = chunkSCIDKAI5_cjs.scopedKey(key, scope);
421
+ const existing = chunkSCIDKAI5_cjs.getRegistered(rKey);
422
422
  if (existing && !existing.isDestroyed) {
423
423
  if (config.warnOnDuplicate) {
424
- chunkZQ2PWVTL_cjs.log("warn", `Duplicate state("${key}") with scope "${scope}". Returning cached instance.`);
424
+ chunkSCIDKAI5_cjs.log("warn", `Duplicate state("${key}") with scope "${scope}". Returning cached instance.`);
425
425
  }
426
426
  return existing;
427
427
  }
428
428
  if (scope === "render" && !options.ssr && !config.ssr) {
429
429
  if (options.sync) {
430
- chunkZQ2PWVTL_cjs.log(
430
+ chunkSCIDKAI5_cjs.log(
431
431
  "warn",
432
432
  `sync: true is ignored for scope "render". Only "local" and "bucket" scopes support cross-tab sync.`
433
433
  );
434
434
  }
435
- const instance = chunkZQ2PWVTL_cjs.createRenderState(key, rKey, options, config);
436
- chunkZQ2PWVTL_cjs.registerByKey(rKey, key, scope, instance, config);
435
+ const instance = chunkSCIDKAI5_cjs.createRenderState(key, rKey, options, config);
436
+ chunkSCIDKAI5_cjs.registerByKey(rKey, key, scope, instance, config);
437
437
  return instance;
438
438
  }
439
- return chunkZQ2PWVTL_cjs.createBase(key, options);
439
+ return chunkSCIDKAI5_cjs.createBase(key, options);
440
440
  }
441
441
 
442
442
  // src/previous.ts
443
443
  var previousCounter = 0;
444
444
  function previous(source, options) {
445
- const listeners = chunkZQ2PWVTL_cjs.createListeners();
445
+ const listeners = chunkSCIDKAI5_cjs.createListeners();
446
446
  const instanceKey = options?.key ?? `previous:${previousCounter++}`;
447
447
  let prev;
448
448
  let current = source.get();
@@ -452,7 +452,7 @@ function previous(source, options) {
452
452
  prev = current;
453
453
  current = next;
454
454
  if (old !== prev) {
455
- chunkZQ2PWVTL_cjs.notify(() => listeners.notify(prev));
455
+ chunkSCIDKAI5_cjs.notify(() => listeners.notify(prev));
456
456
  }
457
457
  });
458
458
  let destroyedPromise;
@@ -514,7 +514,7 @@ function readonly(instance) {
514
514
  // src/select.ts
515
515
  var selectCounter = 0;
516
516
  function select(source, fn, options) {
517
- const listeners = chunkZQ2PWVTL_cjs.createListeners();
517
+ const listeners = chunkSCIDKAI5_cjs.createListeners();
518
518
  const instanceKey = options?.key ?? `select:${selectCounter++}`;
519
519
  let cached;
520
520
  let isDirty = true;
@@ -533,7 +533,7 @@ function select(source, fn, options) {
533
533
  };
534
534
  const markDirty = () => {
535
535
  isDirty = true;
536
- chunkZQ2PWVTL_cjs.notify(notifyListeners);
536
+ chunkSCIDKAI5_cjs.notify(notifyListeners);
537
537
  };
538
538
  const unsubscribe = source.subscribe(markDirty);
539
539
  recompute();
@@ -585,15 +585,15 @@ function select(source, fn, options) {
585
585
 
586
586
  Object.defineProperty(exports, "batch", {
587
587
  enumerable: true,
588
- get: function () { return chunkZQ2PWVTL_cjs.batch; }
588
+ get: function () { return chunkSCIDKAI5_cjs.batch; }
589
589
  });
590
590
  Object.defineProperty(exports, "configure", {
591
591
  enumerable: true,
592
- get: function () { return chunkZQ2PWVTL_cjs.configure; }
592
+ get: function () { return chunkSCIDKAI5_cjs.configure; }
593
593
  });
594
594
  Object.defineProperty(exports, "shallowEqual", {
595
595
  enumerable: true,
596
- get: function () { return chunkZQ2PWVTL_cjs.shallowEqual; }
596
+ get: function () { return chunkSCIDKAI5_cjs.shallowEqual; }
597
597
  });
598
598
  exports.collection = collection;
599
599
  exports.computed = computed;
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-Dr0NA1JQ.cjs';
2
- export { A as Adapter, c as BucketOptions, E as Enhancer, L as Listener, d as Serializer } from './types-Dr0NA1JQ.cjs';
1
+ import { B as BaseInstance, U as Unsubscribe, S as StateOptions, R as ReadonlyInstance, a as Scope, b as StateInstance } from './types-BQb8Z14O.cjs';
2
+ export { A as Adapter, c as BucketOptions, E as Enhancer, L as Listener, d as Serializer } from './types-BQb8Z14O.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-Dr0NA1JQ.js';
2
- export { A as Adapter, c as BucketOptions, E as Enhancer, L as Listener, d as Serializer } from './types-Dr0NA1JQ.js';
1
+ import { B as BaseInstance, U as Unsubscribe, S as StateOptions, R as ReadonlyInstance, a as Scope, b as StateInstance } from './types-BQb8Z14O.js';
2
+ export { A as Adapter, c as BucketOptions, E as Enhancer, L as Listener, d as Serializer } from './types-BQb8Z14O.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, getConfig, scopedKey, getRegistered, log, createRenderState, registerByKey, notify } from './chunk-WLY6NN5P.js';
2
- export { batch, configure, shallowEqual } from './chunk-WLY6NN5P.js';
1
+ import { createBase, createListeners, getRegistry, getConfig, scopedKey, getRegistered, log, createRenderState, registerByKey, notify } from './chunk-Z32544QA.js';
2
+ export { batch, configure, shallowEqual } from './chunk-Z32544QA.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 chunkZQ2PWVTL_cjs = require('./chunk-ZQ2PWVTL.cjs');
3
+ var chunkSCIDKAI5_cjs = require('./chunk-SCIDKAI5.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 = chunkZQ2PWVTL_cjs.createListeners();
12
+ const listeners = chunkSCIDKAI5_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
- chunkZQ2PWVTL_cjs.notify(notifyListeners);
34
+ chunkSCIDKAI5_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
- chunkZQ2PWVTL_cjs.registerServerAdapter(createServerAdapter);
42
+ chunkSCIDKAI5_cjs.registerServerAdapter(createServerAdapter);
43
43
 
44
44
  exports.createServerAdapter = createServerAdapter;
45
45
  exports.withServerSession = withServerSession;
package/dist/server.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as Adapter } from './types-Dr0NA1JQ.cjs';
1
+ import { A as Adapter } from './types-BQb8Z14O.cjs';
2
2
 
3
3
  declare function withServerSession<T>(fn: () => T): Promise<T>;
4
4
  declare function createServerAdapter<T>(key: string, defaultValue: T): Adapter<T>;
package/dist/server.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as Adapter } from './types-Dr0NA1JQ.js';
1
+ import { A as Adapter } from './types-BQb8Z14O.js';
2
2
 
3
3
  declare function withServerSession<T>(fn: () => T): Promise<T>;
4
4
  declare function createServerAdapter<T>(key: string, defaultValue: T): Adapter<T>;
package/dist/server.js CHANGED
@@ -1,4 +1,4 @@
1
- import { registerServerAdapter, createListeners, notify } from './chunk-WLY6NN5P.js';
1
+ import { registerServerAdapter, createListeners, notify } from './chunk-Z32544QA.js';
2
2
  import { AsyncLocalStorage } from 'async_hooks';
3
3
 
4
4
  var als = new AsyncLocalStorage();
@@ -56,11 +56,11 @@ interface BaseInstance<T> extends ReadonlyInstance<T> {
56
56
  */
57
57
  intercept(fn: (next: T, prev: T) => T): Unsubscribe;
58
58
  /**
59
- * Register a post-set tap that fires after each set/reset.
59
+ * Register a handler that fires after each set/reset.
60
60
  * Receives `(next, prev)`. Return value is ignored.
61
- * Multiple hooks run in registration order.
61
+ * Multiple handlers run in registration order.
62
62
  */
63
- use(fn: (next: T, prev: T) => void): Unsubscribe;
63
+ onChange(fn: (next: T, prev: T) => void): Unsubscribe;
64
64
  }
65
65
  type Enhancer<TIn, TOut extends TIn> = (instance: TIn) => TOut;
66
66
  interface StateInstance<T> extends BaseInstance<T> {
@@ -56,11 +56,11 @@ interface BaseInstance<T> extends ReadonlyInstance<T> {
56
56
  */
57
57
  intercept(fn: (next: T, prev: T) => T): Unsubscribe;
58
58
  /**
59
- * Register a post-set tap that fires after each set/reset.
59
+ * Register a handler that fires after each set/reset.
60
60
  * Receives `(next, prev)`. Return value is ignored.
61
- * Multiple hooks run in registration order.
61
+ * Multiple handlers run in registration order.
62
62
  */
63
- use(fn: (next: T, prev: T) => void): Unsubscribe;
63
+ onChange(fn: (next: T, prev: T) => void): Unsubscribe;
64
64
  }
65
65
  type Enhancer<TIn, TOut extends TIn> = (instance: TIn) => TOut;
66
66
  interface StateInstance<T> extends BaseInstance<T> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gjendje",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "description": "TypeScript state management",
5
5
  "keywords": [
6
6
  "state",