@thi.ng/interceptors 3.1.26 → 3.2.1
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 +14 -19
- package/api.d.ts +7 -7
- package/event-bus.d.ts +52 -50
- package/event-bus.js +52 -50
- package/interceptors.d.ts +5 -5
- package/interceptors.js +5 -5
- package/package.json +17 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-
|
|
3
|
+
- **Last updated**: 2022-12-20T16:33:11Z
|
|
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.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/interceptors@3.2.0) (2022-12-16)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- fix [#358](https://github.com/thi-ng/umbrella/issues/358) add "completed" project status, update pkgs/readmes ([d35fa52](https://github.com/thi-ng/umbrella/commit/d35fa52))
|
|
17
|
+
|
|
12
18
|
## [3.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/interceptors@3.1.0) (2021-11-17)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
<!-- This file is generated - DO NOT EDIT! -->
|
|
2
2
|
|
|
3
|
-
# 
|
|
3
|
+
# 
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@thi.ng/interceptors)
|
|
6
6
|

|
|
7
|
-
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
This project is part of the
|
|
10
10
|
[@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo.
|
|
11
11
|
|
|
12
|
+
**Update 12/2022: This package is considered completed and no longer being
|
|
13
|
+
updated with new features. Please consider using
|
|
14
|
+
[@thi.ng/rstream](https://github.com/thi-ng/umbrella/tree/develop/packages/rstream)
|
|
15
|
+
instead...**
|
|
16
|
+
|
|
12
17
|
- [About](#about)
|
|
13
18
|
- [Event bus, interceptors, side effects](#event-bus-interceptors-side-effects)
|
|
14
19
|
- [Interceptors: Event and Effect primitives](#interceptors-event-and-effect-primitives)
|
|
@@ -22,13 +27,11 @@ This project is part of the
|
|
|
22
27
|
- [Usage examples](#usage-examples)
|
|
23
28
|
- [API](#api)
|
|
24
29
|
- [Authors](#authors)
|
|
25
|
-
- [Maintainer](#maintainer)
|
|
26
|
-
- [Contributors](#contributors)
|
|
27
30
|
- [License](#license)
|
|
28
31
|
|
|
29
32
|
## About
|
|
30
33
|
|
|
31
|
-
Interceptor based event bus, side effect & immutable state handling
|
|
34
|
+
Interceptor based event bus, side effect & immutable state handling
|
|
32
35
|
|
|
33
36
|
## Event bus, interceptors, side effects
|
|
34
37
|
|
|
@@ -117,7 +120,7 @@ commented source code and examples for now:
|
|
|
117
120
|
|
|
118
121
|
## Status
|
|
119
122
|
|
|
120
|
-
**
|
|
123
|
+
**COMPLETED** - no further development planned
|
|
121
124
|
|
|
122
125
|
[Search or submit any issues for this package](https://github.com/thi-ng/umbrella/issues?q=%5Binterceptors%5D+in%3Atitle)
|
|
123
126
|
|
|
@@ -143,11 +146,8 @@ ES module import:
|
|
|
143
146
|
|
|
144
147
|
For Node.js REPL:
|
|
145
148
|
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
node --experimental-repl-await
|
|
149
|
-
|
|
150
|
-
> const interceptors = await import("@thi.ng/interceptors");
|
|
149
|
+
```js
|
|
150
|
+
const interceptors = await import("@thi.ng/interceptors");
|
|
151
151
|
```
|
|
152
152
|
|
|
153
153
|
Package sizes (brotli'd, pre-treeshake): ESM: 2.04 KB
|
|
@@ -188,13 +188,8 @@ TODO
|
|
|
188
188
|
|
|
189
189
|
## Authors
|
|
190
190
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
- Karsten Schmidt ([@postspectacular](https://github.com/postspectacular))
|
|
194
|
-
|
|
195
|
-
### Contributors
|
|
196
|
-
|
|
197
|
-
- Logan Powell ([@loganpowell](https://github.com/loganpowell))
|
|
191
|
+
- [Karsten Schmidt](https://thi.ng) (Main author)
|
|
192
|
+
- [Logan Powell](https://github.com/loganpowell)
|
|
198
193
|
|
|
199
194
|
If this project contributes to an academic publication, please cite it as:
|
|
200
195
|
|
|
@@ -209,4 +204,4 @@ If this project contributes to an academic publication, please cite it as:
|
|
|
209
204
|
|
|
210
205
|
## License
|
|
211
206
|
|
|
212
|
-
© 2016 - 2022 Karsten Schmidt // Apache
|
|
207
|
+
© 2016 - 2022 Karsten Schmidt // Apache License 2.0
|
package/api.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { ReadonlyAtom } from "@thi.ng/atom";
|
|
2
2
|
import type { ILogger } from "@thi.ng/logger";
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
3
|
+
export type InterceptorFn = (state: any, e: Event, bus: IDispatch, ctx: InterceptorContext) => InterceptorContext | void;
|
|
4
|
+
export type InterceptorPredicate = (state: any, e: Event, bus: IDispatch, ctx: InterceptorContext) => boolean;
|
|
5
|
+
export type SideEffect = (x: any, bus: IDispatch, ctx: InterceptorContext) => any;
|
|
6
|
+
export type EventDef = Interceptor | InterceptorFn | (Interceptor | InterceptorFn)[];
|
|
7
|
+
export type EffectDef = SideEffect | [SideEffect, number];
|
|
8
|
+
export type AsyncEffectDef = [string, any, string, string];
|
|
9
|
+
export type EffectPriority = [string, number];
|
|
10
10
|
export declare const EV_SET_VALUE = "--set-value";
|
|
11
11
|
export declare const EV_UPDATE_VALUE = "--update-value";
|
|
12
12
|
export declare const EV_TOGGLE_VALUE = "--toggle-value";
|
package/event-bus.d.ts
CHANGED
|
@@ -81,9 +81,8 @@ export declare class StatelessEventBus implements IDispatch {
|
|
|
81
81
|
* Adds built-in event & side effect handlers.
|
|
82
82
|
*
|
|
83
83
|
* @remarks
|
|
84
|
-
* Also see additional built-ins defined by the stateful
|
|
85
|
-
*
|
|
86
|
-
* these class methods:
|
|
84
|
+
* Also see additional built-ins defined by the stateful {@link EventBus}
|
|
85
|
+
* extension of this class, as well as comments for these class methods:
|
|
87
86
|
*
|
|
88
87
|
* - {@link StatelessEventBus.mergeEffects}
|
|
89
88
|
* - {@link StatelessEventBus.processEvent}
|
|
@@ -96,8 +95,8 @@ export declare class StatelessEventBus implements IDispatch {
|
|
|
96
95
|
*
|
|
97
96
|
* #### `FX_CANCEL`
|
|
98
97
|
*
|
|
99
|
-
* If assigned `true`, cancels processing of current event, though
|
|
100
|
-
*
|
|
98
|
+
* If assigned `true`, cancels processing of current event, though still
|
|
99
|
+
* applies any side effects already accumulated.
|
|
101
100
|
*
|
|
102
101
|
* #### `FX_DISPATCH`
|
|
103
102
|
*
|
|
@@ -109,8 +108,8 @@ export declare class StatelessEventBus implements IDispatch {
|
|
|
109
108
|
*
|
|
110
109
|
* #### `FX_DISPATCH_NOW`
|
|
111
110
|
*
|
|
112
|
-
* Dispatches assigned events as part of currently processed event
|
|
113
|
-
*
|
|
111
|
+
* Dispatches assigned events as part of currently processed event queue (no
|
|
112
|
+
* delay).
|
|
114
113
|
*
|
|
115
114
|
* #### `FX_DELAY`
|
|
116
115
|
*
|
|
@@ -125,13 +124,13 @@ export declare class StatelessEventBus implements IDispatch {
|
|
|
125
124
|
* #### `FX_FETCH`
|
|
126
125
|
*
|
|
127
126
|
* Async side effect. Only to be used in conjunction with
|
|
128
|
-
* `FX_DISPATCH_ASYNC`. Performs `fetch()` HTTP request and triggers
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
127
|
+
* `FX_DISPATCH_ASYNC`. Performs `fetch()` HTTP request and triggers success
|
|
128
|
+
* with received response, or if there was an error with response's
|
|
129
|
+
* `statusText`. The error event is only triggered if the fetched response's
|
|
130
|
+
* `ok` field is non-truthy.
|
|
132
131
|
*
|
|
133
|
-
* -
|
|
134
|
-
* -
|
|
132
|
+
* - https://developer.mozilla.org/en-US/docs/Web/API/Response/ok
|
|
133
|
+
* - https://developer.mozilla.org/en-US/docs/Web/API/Response/statusText
|
|
135
134
|
*
|
|
136
135
|
* ```
|
|
137
136
|
* // fetches "foo.json" and then dispatches EV_SUCCESS or EV_ERROR event
|
|
@@ -301,25 +300,25 @@ export declare class StatelessEventBus implements IDispatch {
|
|
|
301
300
|
* Stateful version of {@link StatelessEventBus}.
|
|
302
301
|
*
|
|
303
302
|
* @remarks
|
|
304
|
-
* Wraps an
|
|
305
|
-
* `Atom`/`Cursor`/`History`) and provides additional
|
|
306
|
-
* handlers and side effects to manipulate wrapped state.
|
|
307
|
-
* the default implementation for most use cases.
|
|
303
|
+
* Wraps an [`IAtom`](https://docs.thi.ng/umbrella/atom/interfaces/IAtom.html)
|
|
304
|
+
* state container (i.e. `Atom`/`Cursor`/`History`) and provides additional
|
|
305
|
+
* pre-defined event handlers and side effects to manipulate wrapped state.
|
|
306
|
+
* Prefer this as the default implementation for most use cases.
|
|
308
307
|
*/
|
|
309
308
|
export declare class EventBus extends StatelessEventBus implements IDeref<any>, IDispatch {
|
|
310
309
|
readonly state: IAtom<any>;
|
|
311
310
|
/**
|
|
312
|
-
* Creates a new event bus instance with given parent state, handler
|
|
313
|
-
*
|
|
311
|
+
* Creates a new event bus instance with given parent state, handler and
|
|
312
|
+
* effect definitions (all optional).
|
|
314
313
|
*
|
|
315
314
|
* @remarks
|
|
316
315
|
* If no state is given, automatically creates an
|
|
317
|
-
*
|
|
316
|
+
* [`Atom`](https://docs.thi.ng/umbrella/atom/classes/Atom.html) with empty
|
|
317
|
+
* state object.
|
|
318
318
|
*
|
|
319
319
|
* In addition to the user provided handlers & effects, a number of
|
|
320
|
-
* built-ins are added automatically. See
|
|
321
|
-
*
|
|
322
|
-
* built-ins.
|
|
320
|
+
* built-ins are added automatically. See {@link EventBus.addBuiltIns}. User
|
|
321
|
+
* handlers can override built-ins.
|
|
323
322
|
*
|
|
324
323
|
* @param state -
|
|
325
324
|
* @param handlers -
|
|
@@ -340,7 +339,7 @@ export declare class EventBus extends StatelessEventBus implements IDeref<any>,
|
|
|
340
339
|
* #### `EV_SET_VALUE`
|
|
341
340
|
*
|
|
342
341
|
* Resets state path to provided value. See
|
|
343
|
-
*
|
|
342
|
+
* [`setIn()`](https://docs.thi.ng/umbrella/paths/functions/setIn.html).
|
|
344
343
|
*
|
|
345
344
|
* Example event definition:
|
|
346
345
|
* ```
|
|
@@ -349,8 +348,9 @@ export declare class EventBus extends StatelessEventBus implements IDeref<any>,
|
|
|
349
348
|
*
|
|
350
349
|
* #### `EV_UPDATE_VALUE`
|
|
351
350
|
*
|
|
352
|
-
* Updates a state path's value with provided function and optional
|
|
353
|
-
*
|
|
351
|
+
* Updates a state path's value with provided function and optional extra
|
|
352
|
+
* arguments. See
|
|
353
|
+
* [`updateIn()`](https://docs.thi.ng/umbrella/paths/functions/updateIn.html).
|
|
354
354
|
*
|
|
355
355
|
* Example event definition:
|
|
356
356
|
* ```
|
|
@@ -368,18 +368,19 @@ export declare class EventBus extends StatelessEventBus implements IDeref<any>,
|
|
|
368
368
|
*
|
|
369
369
|
* #### `EV_UNDO`
|
|
370
370
|
*
|
|
371
|
-
* Calls `ctx[id].undo()` and uses return value as new state.
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
* This is useful for
|
|
379
|
-
* after a successful undo
|
|
380
|
-
* undo's are possible. The new
|
|
381
|
-
* frame and has access to the
|
|
382
|
-
* structure for these options is shown
|
|
371
|
+
* Calls `ctx[id].undo()` and uses return value as new state. Assumes
|
|
372
|
+
* `ctx[id]` is a
|
|
373
|
+
* [`History`](https://docs.thi.ng/umbrella/atom/classes/History.html)
|
|
374
|
+
* instance, provided via e.g. `processQueue({ history })`. The event can be
|
|
375
|
+
* triggered with or without ID. By default `"history"` is used as default
|
|
376
|
+
* key to lookup the `History` instance. Furthermore, an additional event
|
|
377
|
+
* can be triggered based on if a previous state has been restored or not
|
|
378
|
+
* (basically, if the undo was successful). This is useful for
|
|
379
|
+
* resetting/re-initializing stateful resources after a successful undo
|
|
380
|
+
* action or to notify the user that no more undo's are possible. The new
|
|
381
|
+
* event will be processed in the same frame and has access to the
|
|
382
|
+
* (possibly) restored state. The event structure for these options is shown
|
|
383
|
+
* below:
|
|
383
384
|
*
|
|
384
385
|
* ```
|
|
385
386
|
* // using default ID
|
|
@@ -400,26 +401,27 @@ export declare class EventBus extends StatelessEventBus implements IDeref<any>,
|
|
|
400
401
|
*
|
|
401
402
|
* #### `FX_STATE`
|
|
402
403
|
*
|
|
403
|
-
* Resets state atom to provided value (only a single update per
|
|
404
|
-
*
|
|
404
|
+
* Resets state atom to provided value (only a single update per processing
|
|
405
|
+
* frame).
|
|
405
406
|
*/
|
|
406
407
|
addBuiltIns(): any;
|
|
407
408
|
/**
|
|
408
|
-
* Triggers processing of current event queue and returns `true` if
|
|
409
|
-
*
|
|
409
|
+
* Triggers processing of current event queue and returns `true` if the any
|
|
410
|
+
* of the processed events caused a state change.
|
|
410
411
|
*
|
|
411
|
-
* If an event handler triggers the `FX_DISPATCH_NOW` side effect,
|
|
412
|
-
*
|
|
413
|
-
*
|
|
412
|
+
* If an event handler triggers the `FX_DISPATCH_NOW` side effect, the new
|
|
413
|
+
* event will be added to the currently processed batch and therefore
|
|
414
|
+
* executed in the same frame. Also see {@link dispatchNow}.
|
|
414
415
|
*
|
|
415
416
|
* If the optional `ctx` arg is provided it will be merged into the
|
|
416
417
|
* {@link InterceptorContext} object passed to each interceptor. Since the
|
|
417
|
-
* merged object is also used to collect triggered side effects,
|
|
418
|
-
*
|
|
418
|
+
* merged object is also used to collect triggered side effects, care must
|
|
419
|
+
* be taken that there're no key name clashes.
|
|
419
420
|
*
|
|
420
|
-
* In order to use the built-in `EV_UNDO`, `EV_REDO` events, users
|
|
421
|
-
*
|
|
422
|
-
*
|
|
421
|
+
* In order to use the built-in `EV_UNDO`, `EV_REDO` events, users MUST
|
|
422
|
+
* provide a
|
|
423
|
+
* [`History`](https://docs.thi.ng/umbrella/atom/classes/History.html) (or
|
|
424
|
+
* compatible undo history instance) via the `ctx` arg, e.g.
|
|
423
425
|
*
|
|
424
426
|
* ```
|
|
425
427
|
* bus.processQueue({ history });
|
package/event-bus.js
CHANGED
|
@@ -92,9 +92,8 @@ export class StatelessEventBus {
|
|
|
92
92
|
* Adds built-in event & side effect handlers.
|
|
93
93
|
*
|
|
94
94
|
* @remarks
|
|
95
|
-
* Also see additional built-ins defined by the stateful
|
|
96
|
-
*
|
|
97
|
-
* these class methods:
|
|
95
|
+
* Also see additional built-ins defined by the stateful {@link EventBus}
|
|
96
|
+
* extension of this class, as well as comments for these class methods:
|
|
98
97
|
*
|
|
99
98
|
* - {@link StatelessEventBus.mergeEffects}
|
|
100
99
|
* - {@link StatelessEventBus.processEvent}
|
|
@@ -107,8 +106,8 @@ export class StatelessEventBus {
|
|
|
107
106
|
*
|
|
108
107
|
* #### `FX_CANCEL`
|
|
109
108
|
*
|
|
110
|
-
* If assigned `true`, cancels processing of current event, though
|
|
111
|
-
*
|
|
109
|
+
* If assigned `true`, cancels processing of current event, though still
|
|
110
|
+
* applies any side effects already accumulated.
|
|
112
111
|
*
|
|
113
112
|
* #### `FX_DISPATCH`
|
|
114
113
|
*
|
|
@@ -120,8 +119,8 @@ export class StatelessEventBus {
|
|
|
120
119
|
*
|
|
121
120
|
* #### `FX_DISPATCH_NOW`
|
|
122
121
|
*
|
|
123
|
-
* Dispatches assigned events as part of currently processed event
|
|
124
|
-
*
|
|
122
|
+
* Dispatches assigned events as part of currently processed event queue (no
|
|
123
|
+
* delay).
|
|
125
124
|
*
|
|
126
125
|
* #### `FX_DELAY`
|
|
127
126
|
*
|
|
@@ -136,13 +135,13 @@ export class StatelessEventBus {
|
|
|
136
135
|
* #### `FX_FETCH`
|
|
137
136
|
*
|
|
138
137
|
* Async side effect. Only to be used in conjunction with
|
|
139
|
-
* `FX_DISPATCH_ASYNC`. Performs `fetch()` HTTP request and triggers
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
138
|
+
* `FX_DISPATCH_ASYNC`. Performs `fetch()` HTTP request and triggers success
|
|
139
|
+
* with received response, or if there was an error with response's
|
|
140
|
+
* `statusText`. The error event is only triggered if the fetched response's
|
|
141
|
+
* `ok` field is non-truthy.
|
|
143
142
|
*
|
|
144
|
-
* -
|
|
145
|
-
* -
|
|
143
|
+
* - https://developer.mozilla.org/en-US/docs/Web/API/Response/ok
|
|
144
|
+
* - https://developer.mozilla.org/en-US/docs/Web/API/Response/statusText
|
|
146
145
|
*
|
|
147
146
|
* ```
|
|
148
147
|
* // fetches "foo.json" and then dispatches EV_SUCCESS or EV_ERROR event
|
|
@@ -521,24 +520,24 @@ export class StatelessEventBus {
|
|
|
521
520
|
* Stateful version of {@link StatelessEventBus}.
|
|
522
521
|
*
|
|
523
522
|
* @remarks
|
|
524
|
-
* Wraps an
|
|
525
|
-
* `Atom`/`Cursor`/`History`) and provides additional
|
|
526
|
-
* handlers and side effects to manipulate wrapped state.
|
|
527
|
-
* the default implementation for most use cases.
|
|
523
|
+
* Wraps an [`IAtom`](https://docs.thi.ng/umbrella/atom/interfaces/IAtom.html)
|
|
524
|
+
* state container (i.e. `Atom`/`Cursor`/`History`) and provides additional
|
|
525
|
+
* pre-defined event handlers and side effects to manipulate wrapped state.
|
|
526
|
+
* Prefer this as the default implementation for most use cases.
|
|
528
527
|
*/
|
|
529
528
|
export class EventBus extends StatelessEventBus {
|
|
530
529
|
/**
|
|
531
|
-
* Creates a new event bus instance with given parent state, handler
|
|
532
|
-
*
|
|
530
|
+
* Creates a new event bus instance with given parent state, handler and
|
|
531
|
+
* effect definitions (all optional).
|
|
533
532
|
*
|
|
534
533
|
* @remarks
|
|
535
534
|
* If no state is given, automatically creates an
|
|
536
|
-
*
|
|
535
|
+
* [`Atom`](https://docs.thi.ng/umbrella/atom/classes/Atom.html) with empty
|
|
536
|
+
* state object.
|
|
537
537
|
*
|
|
538
538
|
* In addition to the user provided handlers & effects, a number of
|
|
539
|
-
* built-ins are added automatically. See
|
|
540
|
-
*
|
|
541
|
-
* built-ins.
|
|
539
|
+
* built-ins are added automatically. See {@link EventBus.addBuiltIns}. User
|
|
540
|
+
* handlers can override built-ins.
|
|
542
541
|
*
|
|
543
542
|
* @param state -
|
|
544
543
|
* @param handlers -
|
|
@@ -564,7 +563,7 @@ export class EventBus extends StatelessEventBus {
|
|
|
564
563
|
* #### `EV_SET_VALUE`
|
|
565
564
|
*
|
|
566
565
|
* Resets state path to provided value. See
|
|
567
|
-
*
|
|
566
|
+
* [`setIn()`](https://docs.thi.ng/umbrella/paths/functions/setIn.html).
|
|
568
567
|
*
|
|
569
568
|
* Example event definition:
|
|
570
569
|
* ```
|
|
@@ -573,8 +572,9 @@ export class EventBus extends StatelessEventBus {
|
|
|
573
572
|
*
|
|
574
573
|
* #### `EV_UPDATE_VALUE`
|
|
575
574
|
*
|
|
576
|
-
* Updates a state path's value with provided function and optional
|
|
577
|
-
*
|
|
575
|
+
* Updates a state path's value with provided function and optional extra
|
|
576
|
+
* arguments. See
|
|
577
|
+
* [`updateIn()`](https://docs.thi.ng/umbrella/paths/functions/updateIn.html).
|
|
578
578
|
*
|
|
579
579
|
* Example event definition:
|
|
580
580
|
* ```
|
|
@@ -592,18 +592,19 @@ export class EventBus extends StatelessEventBus {
|
|
|
592
592
|
*
|
|
593
593
|
* #### `EV_UNDO`
|
|
594
594
|
*
|
|
595
|
-
* Calls `ctx[id].undo()` and uses return value as new state.
|
|
596
|
-
*
|
|
597
|
-
*
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
* This is useful for
|
|
603
|
-
* after a successful undo
|
|
604
|
-
* undo's are possible. The new
|
|
605
|
-
* frame and has access to the
|
|
606
|
-
* structure for these options is shown
|
|
595
|
+
* Calls `ctx[id].undo()` and uses return value as new state. Assumes
|
|
596
|
+
* `ctx[id]` is a
|
|
597
|
+
* [`History`](https://docs.thi.ng/umbrella/atom/classes/History.html)
|
|
598
|
+
* instance, provided via e.g. `processQueue({ history })`. The event can be
|
|
599
|
+
* triggered with or without ID. By default `"history"` is used as default
|
|
600
|
+
* key to lookup the `History` instance. Furthermore, an additional event
|
|
601
|
+
* can be triggered based on if a previous state has been restored or not
|
|
602
|
+
* (basically, if the undo was successful). This is useful for
|
|
603
|
+
* resetting/re-initializing stateful resources after a successful undo
|
|
604
|
+
* action or to notify the user that no more undo's are possible. The new
|
|
605
|
+
* event will be processed in the same frame and has access to the
|
|
606
|
+
* (possibly) restored state. The event structure for these options is shown
|
|
607
|
+
* below:
|
|
607
608
|
*
|
|
608
609
|
* ```
|
|
609
610
|
* // using default ID
|
|
@@ -624,8 +625,8 @@ export class EventBus extends StatelessEventBus {
|
|
|
624
625
|
*
|
|
625
626
|
* #### `FX_STATE`
|
|
626
627
|
*
|
|
627
|
-
* Resets state atom to provided value (only a single update per
|
|
628
|
-
*
|
|
628
|
+
* Resets state atom to provided value (only a single update per processing
|
|
629
|
+
* frame).
|
|
629
630
|
*/
|
|
630
631
|
addBuiltIns() {
|
|
631
632
|
super.addBuiltIns();
|
|
@@ -649,21 +650,22 @@ export class EventBus extends StatelessEventBus {
|
|
|
649
650
|
});
|
|
650
651
|
}
|
|
651
652
|
/**
|
|
652
|
-
* Triggers processing of current event queue and returns `true` if
|
|
653
|
-
*
|
|
653
|
+
* Triggers processing of current event queue and returns `true` if the any
|
|
654
|
+
* of the processed events caused a state change.
|
|
654
655
|
*
|
|
655
|
-
* If an event handler triggers the `FX_DISPATCH_NOW` side effect,
|
|
656
|
-
*
|
|
657
|
-
*
|
|
656
|
+
* If an event handler triggers the `FX_DISPATCH_NOW` side effect, the new
|
|
657
|
+
* event will be added to the currently processed batch and therefore
|
|
658
|
+
* executed in the same frame. Also see {@link dispatchNow}.
|
|
658
659
|
*
|
|
659
660
|
* If the optional `ctx` arg is provided it will be merged into the
|
|
660
661
|
* {@link InterceptorContext} object passed to each interceptor. Since the
|
|
661
|
-
* merged object is also used to collect triggered side effects,
|
|
662
|
-
*
|
|
662
|
+
* merged object is also used to collect triggered side effects, care must
|
|
663
|
+
* be taken that there're no key name clashes.
|
|
663
664
|
*
|
|
664
|
-
* In order to use the built-in `EV_UNDO`, `EV_REDO` events, users
|
|
665
|
-
*
|
|
666
|
-
*
|
|
665
|
+
* In order to use the built-in `EV_UNDO`, `EV_REDO` events, users MUST
|
|
666
|
+
* provide a
|
|
667
|
+
* [`History`](https://docs.thi.ng/umbrella/atom/classes/History.html) (or
|
|
668
|
+
* compatible undo history instance) via the `ctx` arg, e.g.
|
|
667
669
|
*
|
|
668
670
|
* ```
|
|
669
671
|
* bus.processQueue({ history });
|
package/interceptors.d.ts
CHANGED
|
@@ -27,11 +27,11 @@ export declare const dispatch: (event: Event) => InterceptorFn;
|
|
|
27
27
|
*/
|
|
28
28
|
export declare const dispatchNow: (event: Event) => InterceptorFn;
|
|
29
29
|
/**
|
|
30
|
-
* Higher-order interceptor. Returns interceptor which calls
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* {@link EventBus.processQueue}. The default ID for the history
|
|
30
|
+
* Higher-order interceptor. Returns interceptor which calls `ctx[id].record()`,
|
|
31
|
+
* where `ctx` is the currently active {@link InterceptorContext} passed to all
|
|
32
|
+
* event handlers and `ctx[id]` is assumed to be a
|
|
33
|
+
* [`History`](https://docs.thi.ng/umbrella/atom/classes/History.html) instance,
|
|
34
|
+
* passed to {@link EventBus.processQueue}. The default ID for the history
|
|
35
35
|
* instance is `"history"`.
|
|
36
36
|
*
|
|
37
37
|
* Example usage:
|
package/interceptors.js
CHANGED
|
@@ -33,11 +33,11 @@ export const dispatchNow = (event) => () => ({
|
|
|
33
33
|
[FX_DISPATCH_NOW]: event,
|
|
34
34
|
});
|
|
35
35
|
/**
|
|
36
|
-
* Higher-order interceptor. Returns interceptor which calls
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* {@link EventBus.processQueue}. The default ID for the history
|
|
36
|
+
* Higher-order interceptor. Returns interceptor which calls `ctx[id].record()`,
|
|
37
|
+
* where `ctx` is the currently active {@link InterceptorContext} passed to all
|
|
38
|
+
* event handlers and `ctx[id]` is assumed to be a
|
|
39
|
+
* [`History`](https://docs.thi.ng/umbrella/atom/classes/History.html) instance,
|
|
40
|
+
* passed to {@link EventBus.processQueue}. The default ID for the history
|
|
41
41
|
* instance is `"history"`.
|
|
42
42
|
*
|
|
43
43
|
* Example usage:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/interceptors",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "Interceptor based event bus, side effect & immutable state handling",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -21,7 +21,10 @@
|
|
|
21
21
|
"url": "https://patreon.com/thing_umbrella"
|
|
22
22
|
}
|
|
23
23
|
],
|
|
24
|
-
"author": "Karsten Schmidt
|
|
24
|
+
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
|
+
"contributors": [
|
|
26
|
+
"Logan Powell (https://github.com/loganpowell)"
|
|
27
|
+
],
|
|
25
28
|
"license": "Apache-2.0",
|
|
26
29
|
"scripts": {
|
|
27
30
|
"build": "yarn clean && tsc --declaration",
|
|
@@ -34,20 +37,20 @@
|
|
|
34
37
|
"test": "testament test"
|
|
35
38
|
},
|
|
36
39
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.
|
|
38
|
-
"@thi.ng/atom": "^5.1.
|
|
39
|
-
"@thi.ng/checks": "^3.3.
|
|
40
|
-
"@thi.ng/errors": "^2.2.
|
|
41
|
-
"@thi.ng/logger": "^1.4.
|
|
42
|
-
"@thi.ng/paths": "^5.1.
|
|
40
|
+
"@thi.ng/api": "^8.6.1",
|
|
41
|
+
"@thi.ng/atom": "^5.1.26",
|
|
42
|
+
"@thi.ng/checks": "^3.3.5",
|
|
43
|
+
"@thi.ng/errors": "^2.2.6",
|
|
44
|
+
"@thi.ng/logger": "^1.4.5",
|
|
45
|
+
"@thi.ng/paths": "^5.1.26"
|
|
43
46
|
},
|
|
44
47
|
"devDependencies": {
|
|
45
|
-
"@microsoft/api-extractor": "^7.33.
|
|
46
|
-
"@thi.ng/testament": "^0.3.
|
|
48
|
+
"@microsoft/api-extractor": "^7.33.7",
|
|
49
|
+
"@thi.ng/testament": "^0.3.7",
|
|
47
50
|
"rimraf": "^3.0.2",
|
|
48
51
|
"tools": "^0.0.1",
|
|
49
|
-
"typedoc": "^0.23.
|
|
50
|
-
"typescript": "^4.
|
|
52
|
+
"typedoc": "^0.23.22",
|
|
53
|
+
"typescript": "^4.9.4"
|
|
51
54
|
},
|
|
52
55
|
"keywords": [
|
|
53
56
|
"async",
|
|
@@ -88,8 +91,8 @@
|
|
|
88
91
|
"hdom",
|
|
89
92
|
"rdom"
|
|
90
93
|
],
|
|
91
|
-
"status": "
|
|
94
|
+
"status": "completed",
|
|
92
95
|
"year": 2016
|
|
93
96
|
},
|
|
94
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "7b2af448da8a63fb21704a79cc4cdf1f3d7d7a64\n"
|
|
95
98
|
}
|