deno.land / x / feathers@v5.0.0-pre.29 / _feathers / events.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// DO NOT MODIFY - generated from packages/feathers/src/events.ts
import { NextFunction, EventEmitter } from './dependencies.ts';import { HookContext, FeathersService } from './declarations.ts';import { getServiceOptions, defaultEventMap } from './service.ts';
export function eventHook (context: HookContext, next: NextFunction) { const { events } = getServiceOptions((context as any).self); const defaultEvent = (defaultEventMap as any)[context.method] || null;
context.event = defaultEvent;
return next().then(() => { // Send the event only if the service does not do so already (indicated in the `events` option) // This is used for custom events and for client services receiving event from the server if (typeof context.event === 'string' && !events.includes(context.event)) { const results = Array.isArray(context.result) ? context.result : [ context.result ];
results.forEach(element => (context as any).self.emit(context.event, element, context)); } });}
export function eventMixin<A> (service: FeathersService<A>) { const isEmitter = typeof service.on === 'function' && typeof service.emit === 'function';
if (!isEmitter) { Object.assign(service, EventEmitter.prototype); }
return service;}
feathers
The API and real-time application framework
DocumentationDocumentation
GitHub Repositoryfeathersjs/feathers
GitHub Stars
14347

Version Info

Tagged at
4 months ago

External Dependencies

1 external dependency