@bluelibs/runner 3.1.0 → 3.2.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/src/define.ts CHANGED
@@ -179,12 +179,13 @@ export function defineIndex<
179
179
  }
180
180
 
181
181
  export function defineEvent<TPayload = void>(
182
- config: IEventDefinition<TPayload>
182
+ config?: IEventDefinition<TPayload>
183
183
  ): IEvent<TPayload> {
184
184
  const callerFilePath = getCallerFile();
185
+ const eventConfig = config || {};
185
186
  return {
186
- ...config,
187
- id: config.id || generateCallerIdFromFile(callerFilePath, "event"),
187
+ ...eventConfig,
188
+ id: eventConfig.id || generateCallerIdFromFile(callerFilePath, "event"),
188
189
  [symbols.filePath]: callerFilePath,
189
190
  [symbolEvent]: true, // This is a workaround
190
191
  };
package/src/defs.ts CHANGED
@@ -309,6 +309,18 @@ export interface IEventEmission<TPayload = any> {
309
309
  * The source of the event. This can be useful for debugging.
310
310
  */
311
311
  source: string | symbol;
312
+ /**
313
+ * Metadata associated with the event definition.
314
+ */
315
+ meta: IEventMeta;
316
+ /**
317
+ * Stops propagation to remaining event listeners.
318
+ */
319
+ stopPropagation(): void;
320
+ /**
321
+ * Returns true if propagation has been stopped.
322
+ */
323
+ isPropagationStopped(): boolean;
312
324
  }
313
325
 
314
326
  export interface IMiddlewareDefinition<
@@ -316,7 +328,7 @@ export interface IMiddlewareDefinition<
316
328
  TDependencies extends DependencyMapType = any
317
329
  > {
318
330
  id?: string | symbol;
319
- dependencies?: TDependencies | (() => TDependencies);
331
+ dependencies?: TDependencies | ((config: TConfig) => TDependencies);
320
332
  run: (
321
333
  input: IMiddlewareExecutionInput,
322
334
  dependencies: DependencyValuesType<TDependencies>,
@@ -112,14 +112,25 @@ export class EventManager {
112
112
  return;
113
113
  }
114
114
 
115
+ let propagationStopped = false;
116
+
115
117
  const event: IEventEmission = {
116
118
  id: eventDefinition.id,
117
119
  data,
118
120
  timestamp: new Date(),
119
121
  source,
122
+ meta: eventDefinition.meta || {},
123
+ stopPropagation: () => {
124
+ propagationStopped = true;
125
+ },
126
+ isPropagationStopped: () => propagationStopped,
120
127
  };
121
128
 
122
129
  for (const listener of allListeners) {
130
+ if (propagationStopped) {
131
+ break;
132
+ }
133
+
123
134
  if (!listener.filter || listener.filter(event)) {
124
135
  await listener.handler(event);
125
136
  }
@@ -64,7 +64,7 @@ export class StoreRegistry {
64
64
 
65
65
  item.dependencies =
66
66
  typeof item.dependencies === "function"
67
- ? item.dependencies()
67
+ ? item.dependencies(item.config)
68
68
  : item.dependencies;
69
69
 
70
70
  this.middlewares.set(item.id, {