@thi.ng/interceptors 3.2.57 → 3.2.59
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 +7 -1
- package/README.md +1 -1
- package/event-bus.js +6 -6
- package/interceptors.d.ts +18 -8
- package/interceptors.js +4 -4
- package/package.json +13 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-06-21T19:34:38Z
|
|
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
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 193 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(
|
|
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(
|
|
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]:
|
|
606
|
-
[EV_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
|
|
651
|
-
const
|
|
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 {
|
|
42
|
-
* import {
|
|
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 =
|
|
45
|
-
* history =
|
|
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
|
-
*
|
|
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
|
|
24
|
-
const ensureStateLessThan = (max, path, err) => ensurePred((state, e) =>
|
|
25
|
-
const ensureStateGreaterThan = (min, path, err) => ensurePred((state, e) =>
|
|
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 =
|
|
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.
|
|
3
|
+
"version": "3.2.59",
|
|
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://
|
|
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.
|
|
43
|
-
"@thi.ng/atom": "^5.
|
|
44
|
-
"@thi.ng/checks": "^3.6.
|
|
45
|
-
"@thi.ng/errors": "^2.5.
|
|
46
|
-
"@thi.ng/logger": "^3.0.
|
|
47
|
-
"@thi.ng/paths": "^5.1.
|
|
42
|
+
"@thi.ng/api": "^8.11.3",
|
|
43
|
+
"@thi.ng/atom": "^5.3.1",
|
|
44
|
+
"@thi.ng/checks": "^3.6.5",
|
|
45
|
+
"@thi.ng/errors": "^2.5.8",
|
|
46
|
+
"@thi.ng/logger": "^3.0.13",
|
|
47
|
+
"@thi.ng/paths": "^5.1.82"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@microsoft/api-extractor": "^7.
|
|
51
|
-
"esbuild": "^0.
|
|
52
|
-
"typedoc": "^0.25.
|
|
53
|
-
"typescript": "^5.
|
|
50
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
51
|
+
"esbuild": "^0.21.5",
|
|
52
|
+
"typedoc": "^0.25.13",
|
|
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": "
|
|
98
|
+
"gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
|
|
99
99
|
}
|