@searchspring/snap-event-manager 0.70.1 → 0.72.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.
- package/README.md +10 -29
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
# Snap Event Manager
|
|
2
2
|
|
|
3
|
-
<a href="https://www.npmjs.com/package/@searchspring/snap-event-manager"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-event-manager.svg?style=flat"></a>
|
|
4
3
|
|
|
5
|
-
The Snap Event Manager is used to create events and attach middleware to them.
|
|
4
|
+
The Snap Event Manager is available on each controller via `controller.eventManager` and is used to create events and attach middleware to them. Events are recommended to be configured via [Configuration Middleware](https://github.com/searchspring/snap/tree/main/docs/REFERENCE_CONFIGURATION_MIDDLEWARE.md) to hook into controller events at critical times in the life cycle. It also allows for custom events to be used throughout your implementation.
|
|
6
5
|
|
|
7
|
-
When used as a service of a controller it allows you to hook into controller events at critical times in the life cycle. It also allows for custom events to be used throughout your implementation.
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
## Dependency
|
|
11
|
-
|
|
12
|
-
Snap Event Manager is a dependency of [@searchspring/snap-controller](https://github.com/searchspring/snap/tree/main/packages/snap-controller) <a href="https://www.npmjs.com/package/@searchspring/snap-controller"><img alt="NPM Status" src="https://img.shields.io/npm/v/@searchspring/snap-controller.svg?style=flat"></a>
|
|
13
|
-
|
|
14
|
-
## Installation
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
npm install --save @searchspring/snap-event-manager
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Import
|
|
21
|
-
```typescript
|
|
22
|
-
import { EventManager } from '@searchspring/snap-event-manager';
|
|
23
|
-
```
|
|
24
7
|
## Controller usage
|
|
25
8
|
Snap Event Manager is a dependency of Snap Controller and it is recommended to use methods of the controller to attach events to the EventManager. Additionally, different events exist for the different controllers - see the Controller documentation for more details.
|
|
26
9
|
|
|
@@ -28,10 +11,8 @@ Snap Event Manager is a dependency of Snap Controller and it is recommended to u
|
|
|
28
11
|
### `on` method
|
|
29
12
|
Used to attach middleware to an event. If the event name previously had middleware attached, it will add to the middleware stack.
|
|
30
13
|
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
eventManager.on('interestingEvent', async (eventData, next) => {
|
|
14
|
+
```js
|
|
15
|
+
controller.eventManager.on('interestingEvent', async (eventData, next) => {
|
|
35
16
|
// do something with the eventData
|
|
36
17
|
|
|
37
18
|
// pass control to the next middleware attached to the event
|
|
@@ -46,8 +27,8 @@ If a middleware returns `false` the entire middleware flow is interrupted and an
|
|
|
46
27
|
### `fire` method
|
|
47
28
|
Invoke custom event. Data passed into the second parameter gets handed off to the middleware attached with the `on` method.
|
|
48
29
|
|
|
49
|
-
```
|
|
50
|
-
eventManager.fire('interestingEvent', { data: { some: 'string' } });
|
|
30
|
+
```js
|
|
31
|
+
controller.eventManager.fire('interestingEvent', { data: { some: 'string' } });
|
|
51
32
|
```
|
|
52
33
|
|
|
53
34
|
## Middleware
|
|
@@ -58,26 +39,26 @@ The first middleware attached with the `on` method is the first to execute. When
|
|
|
58
39
|
|
|
59
40
|
### Order Flow Example
|
|
60
41
|
|
|
61
|
-
```
|
|
62
|
-
eventManager.on('interestingEvent', async (data, next) => {
|
|
42
|
+
```js
|
|
43
|
+
controller.eventManager.on('interestingEvent', async (data, next) => {
|
|
63
44
|
console.log('first middleware start');
|
|
64
45
|
await next();
|
|
65
46
|
console.log('first middleware end');
|
|
66
47
|
});
|
|
67
48
|
|
|
68
|
-
eventManager.on('interestingEvent', async (data, next) => {
|
|
49
|
+
controller.eventManager.on('interestingEvent', async (data, next) => {
|
|
69
50
|
console.log('second middleware start');
|
|
70
51
|
await next();
|
|
71
52
|
console.log('second middleware end');
|
|
72
53
|
});
|
|
73
54
|
|
|
74
|
-
eventManager.on('interestingEvent', async (data, next) => {
|
|
55
|
+
controller.eventManager.on('interestingEvent', async (data, next) => {
|
|
75
56
|
console.log('third middleware start');
|
|
76
57
|
await next();
|
|
77
58
|
console.log('third middleware end');
|
|
78
59
|
});
|
|
79
60
|
|
|
80
|
-
eventManager.fire('interestingEvent', { data: { some: 'string' } } );
|
|
61
|
+
controller.eventManager.fire('interestingEvent', { data: { some: 'string' } } );
|
|
81
62
|
|
|
82
63
|
```
|
|
83
64
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@searchspring/snap-event-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.72.0",
|
|
4
4
|
"description": "Snap Event Manager",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"files": [
|
|
24
24
|
"dist/**/*"
|
|
25
25
|
],
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "737d4bd308ebbb852fe3f09b2b90f4af87bbe264"
|
|
27
27
|
}
|