mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 12:36:57 +00:00
add ignoreRemote filter to InternalEventService
This commit is contained in:
parent
f446d77cb5
commit
1f2742ddd7
2 changed files with 6 additions and 5 deletions
|
@ -10,10 +10,11 @@ import { GlobalEventService } from '@/core/GlobalEventService.js';
|
||||||
import type { GlobalEvents, InternalEventTypes } from '@/core/GlobalEventService.js';
|
import type { GlobalEvents, InternalEventTypes } from '@/core/GlobalEventService.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
|
|
||||||
export type Listener<K extends keyof InternalEventTypes> = (value: InternalEventTypes[K], key: K) => void | Promise<void>;
|
export type Listener<K extends keyof InternalEventTypes> = (value: InternalEventTypes[K], key: K, isLocal: boolean) => void | Promise<void>;
|
||||||
|
|
||||||
export interface ListenerProps {
|
export interface ListenerProps {
|
||||||
ignoreLocal?: boolean,
|
ignoreLocal?: boolean,
|
||||||
|
ignoreRemote?: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -61,8 +62,8 @@ export class InternalEventService implements OnApplicationShutdown {
|
||||||
|
|
||||||
const promises: Promise<void>[] = [];
|
const promises: Promise<void>[] = [];
|
||||||
for (const [listener, props] of listeners) {
|
for (const [listener, props] of listeners) {
|
||||||
if (!isLocal || !props.ignoreLocal) {
|
if ((isLocal && !props.ignoreLocal) || (!isLocal && !props.ignoreRemote)) {
|
||||||
const promise = Promise.resolve(listener(value, type));
|
const promise = Promise.resolve(listener(value, type, isLocal));
|
||||||
promises.push(promise);
|
promises.push(promise);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,8 +70,8 @@ export class FakeInternalEventService extends InternalEventService {
|
||||||
public async emit<K extends keyof InternalEventTypes>(type: K, value: InternalEventTypes[K], isLocal = true): Promise<void> {
|
public async emit<K extends keyof InternalEventTypes>(type: K, value: InternalEventTypes[K], isLocal = true): Promise<void> {
|
||||||
for (const listener of this._listeners) {
|
for (const listener of this._listeners) {
|
||||||
if (listener[0] === type) {
|
if (listener[0] === type) {
|
||||||
if (!isLocal || !listener[2].ignoreLocal) {
|
if ((isLocal && !listener[2].ignoreLocal) || (!isLocal && !listener[2].ignoreRemote)) {
|
||||||
await listener[1](value, type);
|
await listener[1](value, type, isLocal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue