@thi.ng/interceptors 3.2.58 → 3.2.60

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-05-08T18:24:32Z
3
+ - **Last updated**: 2024-06-29T09:28:36Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [3.2.59](https://github.com/thi-ng/umbrella/tree/@thi.ng/interceptors@3.2.59) (2024-06-21)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
17
+
12
18
  ### [3.2.56](https://github.com/thi-ng/umbrella/tree/@thi.ng/interceptors@3.2.56) (2024-04-20)
13
19
 
14
20
  #### ♻️ Refactoring
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 189 standalone projects, maintained as part
11
11
  > of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
12
12
  > and anti-framework.
13
13
  >
package/event-bus.js CHANGED
@@ -207,7 +207,7 @@ class StatelessEventBus {
207
207
  * @param ids -
208
208
  */
209
209
  instrumentWith(inject, ids) {
210
- const iceps = inject.map(asInterceptor);
210
+ const iceps = inject.map(__asInterceptor);
211
211
  const handlers = this.handlers;
212
212
  for (let id of ids || Object.keys(handlers)) {
213
213
  const h = handlers[id];
@@ -475,7 +475,7 @@ class StatelessEventBus {
475
475
  }
476
476
  }
477
477
  interceptorsFromSpec(spec) {
478
- return isArray(spec) ? spec.map(asInterceptor) : isFunction(spec) ? [{ pre: spec }] : [spec];
478
+ return isArray(spec) ? spec.map(__asInterceptor) : isFunction(spec) ? [{ pre: spec }] : [spec];
479
479
  }
480
480
  }
481
481
  class EventBus extends StatelessEventBus {
@@ -602,8 +602,8 @@ class EventBus extends StatelessEventBus {
602
602
  [EV_TOGGLE_VALUE]: (state, [_, path]) => ({
603
603
  [FX_STATE]: updateInUnsafe(state, path, (x) => !x)
604
604
  }),
605
- [EV_UNDO]: undoHandler("undo"),
606
- [EV_REDO]: undoHandler("redo")
605
+ [EV_UNDO]: __undoHandler("undo"),
606
+ [EV_REDO]: __undoHandler("redo")
607
607
  });
608
608
  this.addEffects({
609
609
  [FX_STATE]: [(state) => this.state.reset(state), -1e3]
@@ -647,8 +647,8 @@ class EventBus extends StatelessEventBus {
647
647
  return false;
648
648
  }
649
649
  }
650
- const asInterceptor = (i) => isFunction(i) ? { pre: i } : i;
651
- const undoHandler = (action) => (_, [__, ev], bus, ctx) => {
650
+ const __asInterceptor = (i) => isFunction(i) ? { pre: i } : i;
651
+ const __undoHandler = (action) => (_, [__, ev], bus, ctx) => {
652
652
  const id = ev ? ev[0] : "history";
653
653
  if (implementsFunction(ctx[id], action)) {
654
654
  const ok = ctx[id][action]();
package/interceptors.d.ts CHANGED
@@ -37,25 +37,35 @@ export declare const dispatchNow: (event: Event) => InterceptorFn;
37
37
  * Example usage:
38
38
  *
39
39
  * @example
40
- * ```ts
41
- * import { Atom } from "@thi.ng/atom";
42
- * import { EvenBus, snapshot, valueSetter } from "@thi.ng/interceptors";
40
+ * ```ts tangle:../export/snapshot.ts
41
+ * import { defAtom, defHistory } from "@thi.ng/atom";
42
+ * import { EventBus, snapshot, valueSetter, EV_UNDO } from "@thi.ng/interceptors";
43
43
  *
44
- * state = new Atom({});
45
- * history = new History(state);
46
- * bus = new EventBus(state);
44
+ * const state = defAtom({ foo: 42 });
45
+ * const history = defHistory(state);
46
+ * const bus = new EventBus(state);
47
47
  * // register event handler
48
48
  * // each time the `foo` event is triggered, a snapshot of
49
49
  * // current app state is recorded first
50
50
  * bus.addHandlers({
51
- * foo: [snapshot(), valueSetter("foo")]
51
+ * foo: [snapshot(), valueSetter("foo")]
52
52
  * });
53
- * ...
53
+ *
54
54
  * // trigger event
55
55
  * bus.dispatch(["foo", 23]);
56
56
  *
57
57
  * // pass history instance via interceptor context to handlers
58
58
  * bus.processQueue({ history });
59
+ *
60
+ * // show updated state
61
+ * console.log(state.deref());
62
+ *
63
+ * // trigger & process built-in undo event
64
+ * bus.dispatch([EV_UNDO]);
65
+ * bus.processQueue({ history });
66
+ *
67
+ * // show restored state
68
+ * console.log(state.deref());
59
69
  * ```
60
70
  *
61
71
  * @param id -
package/interceptors.js CHANGED
@@ -20,11 +20,11 @@ const ensurePred = (pred, err) => (state, e, bus, ctx) => !pred(state, e, bus, c
20
20
  [FX_CANCEL]: true,
21
21
  ...err ? err(state, e, bus, ctx) : null
22
22
  } : void 0;
23
- const eventPathState = (state, path, e) => getInUnsafe(state, path ? path(e) : e[1]);
24
- const ensureStateLessThan = (max, path, err) => ensurePred((state, e) => eventPathState(state, path, e) < max, err);
25
- const ensureStateGreaterThan = (min, path, err) => ensurePred((state, e) => eventPathState(state, path, e) > min, err);
23
+ const __eventPathState = (state, path, e) => getInUnsafe(state, path ? path(e) : e[1]);
24
+ const ensureStateLessThan = (max, path, err) => ensurePred((state, e) => __eventPathState(state, path, e) < max, err);
25
+ const ensureStateGreaterThan = (min, path, err) => ensurePred((state, e) => __eventPathState(state, path, e) > min, err);
26
26
  const ensureStateRange = (min, max, path, err) => ensurePred((state, e) => {
27
- const x = eventPathState(state, path, e);
27
+ const x = __eventPathState(state, path, e);
28
28
  return x >= min && x <= max;
29
29
  }, err);
30
30
  const ensureParamRange = (min, max, value, err) => ensurePred((_, e) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/interceptors",
3
- "version": "3.2.58",
3
+ "version": "3.2.60",
4
4
  "description": "Interceptor based event bus, side effect & immutable state handling",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/thi-ng/umbrella.git"
12
12
  },
13
- "homepage": "https://github.com/thi-ng/umbrella/tree/develop/packages/interceptors#readme",
13
+ "homepage": "https://thi.ng/interceptors",
14
14
  "funding": [
15
15
  {
16
16
  "type": "github",
@@ -39,18 +39,18 @@
39
39
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@thi.ng/api": "^8.11.2",
43
- "@thi.ng/atom": "^5.3.0",
44
- "@thi.ng/checks": "^3.6.4",
45
- "@thi.ng/errors": "^2.5.7",
46
- "@thi.ng/logger": "^3.0.12",
47
- "@thi.ng/paths": "^5.1.81"
42
+ "@thi.ng/api": "^8.11.4",
43
+ "@thi.ng/atom": "^5.3.2",
44
+ "@thi.ng/checks": "^3.6.6",
45
+ "@thi.ng/errors": "^2.5.9",
46
+ "@thi.ng/logger": "^3.0.14",
47
+ "@thi.ng/paths": "^5.1.83"
48
48
  },
49
49
  "devDependencies": {
50
- "@microsoft/api-extractor": "^7.43.2",
51
- "esbuild": "^0.21.1",
50
+ "@microsoft/api-extractor": "^7.47.0",
51
+ "esbuild": "^0.21.5",
52
52
  "typedoc": "^0.25.13",
53
- "typescript": "^5.4.5"
53
+ "typescript": "^5.5.2"
54
54
  },
55
55
  "keywords": [
56
56
  "async",
@@ -95,5 +95,5 @@
95
95
  "status": "completed",
96
96
  "year": 2016
97
97
  },
98
- "gitHead": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
98
+ "gitHead": "7b950c112fba0b2e7c450765b15624c3382f1354\n"
99
99
  }