@adonisjs/events 7.2.1 → 8.1.0-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.
@@ -1,118 +0,0 @@
1
- "use strict";
2
- /*
3
- * @adonisjs/events
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.IocResolver = void 0;
12
- /**
13
- * Resolves string based event listeners from the IoC container. Also this method wraps
14
- * the IoC container bindings in a closure. That closure is later used to remove
15
- * the event listeners properly.
16
- */
17
- class IocResolver {
18
- constructor(app) {
19
- /**
20
- * A reference to the event handlers resolved from the IoC container and
21
- * cached. It is a map of
22
- *
23
- * [event, [namespace, resolvedHandler]]
24
- */
25
- this.eventHandlers = new Map();
26
- /**
27
- * A reference to the catch all event handlers. It is a map of
28
- *
29
- * [namespace, resolvedHandler]
30
- */
31
- this.anyHandlers = new Map();
32
- this.containerResolver = app.container.getResolver(undefined, 'eventListeners', 'App/Listeners');
33
- }
34
- /**
35
- * Returns the listener by resolving the namespace from the IoC container
36
- */
37
- getReferenceListener(handler) {
38
- return (...args) => {
39
- return this.containerResolver.call(handler, this.listenersBaseNamespace, args);
40
- };
41
- }
42
- /**
43
- * Returns all handlers for a given event.
44
- */
45
- getHandlersFor(event) {
46
- if (!this.eventHandlers.has(event)) {
47
- this.eventHandlers.set(event, new Map());
48
- }
49
- return this.eventHandlers.get(event);
50
- }
51
- /**
52
- * Define custom namespace for Event listeners
53
- */
54
- namespace(namespace) {
55
- this.listenersBaseNamespace = namespace;
56
- }
57
- /**
58
- * Returns event handler callback for an IoC container string reference.
59
- * Adding same handler for the same event is noop.
60
- */
61
- getEventHandler(event, handler) {
62
- const handlers = this.getHandlersFor(event);
63
- /**
64
- * Return the existing handler when same handler for the
65
- * same event already exists.
66
- *
67
- * Emittery will also re-use the same handler. So it is a noop
68
- * everywhere.
69
- */
70
- if (handlers.has(handler)) {
71
- return handlers.get(handler);
72
- }
73
- const eventHandler = this.getReferenceListener(handler);
74
- /**
75
- * Store reference to the handler, so that we can clean it off
76
- * later.
77
- */
78
- handlers.set(handler, eventHandler);
79
- return eventHandler;
80
- }
81
- /**
82
- * Removes the event handler from the tracked list and also returns
83
- * it back.
84
- */
85
- removeEventHandler(event, handler) {
86
- const handlers = this.getHandlersFor(event);
87
- const eventHandler = handlers.get(handler);
88
- if (eventHandler) {
89
- handlers.delete(handler);
90
- return eventHandler;
91
- }
92
- return null;
93
- }
94
- /**
95
- * Returns Event handler for wildcard events. Adding the same
96
- * handler for multiple times is a noop.
97
- */
98
- getAnyHandler(handler) {
99
- if (this.anyHandlers.has(handler)) {
100
- return this.anyHandlers.get(handler);
101
- }
102
- const eventHandler = this.getReferenceListener(handler);
103
- this.anyHandlers.set(handler, eventHandler);
104
- return eventHandler;
105
- }
106
- /**
107
- * Removes and returns the handler for a string reference.
108
- */
109
- removeAnyHandler(handler) {
110
- const anyHandler = this.anyHandlers.get(handler);
111
- if (anyHandler) {
112
- this.anyHandlers.delete(handler);
113
- return anyHandler;
114
- }
115
- return null;
116
- }
117
- }
118
- exports.IocResolver = IocResolver;
@@ -1 +0,0 @@
1
- export { Emitter } from './src/Emitter';
@@ -1,13 +0,0 @@
1
- "use strict";
2
- /*
3
- * @adonisjs/events
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.Emitter = void 0;
12
- var Emitter_1 = require("./src/Emitter");
13
- Object.defineProperty(exports, "Emitter", { enumerable: true, get: function () { return Emitter_1.Emitter; } });