forked from nestjs/cqrs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fully-generic-events' of https://github.com/boenrobot/cqrs
- Loading branch information
Showing
14 changed files
with
91 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,4 @@ | |
"git add" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { IEvent } from '../interfaces'; | ||
|
||
export const defaultGetEventName = <EventBase extends IEvent = IEvent>( | ||
event: EventBase, | ||
): string => { | ||
const { constructor } = Object.getPrototypeOf(event); | ||
return constructor.name as string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
import { Subject } from 'rxjs'; | ||
import { IEvent, IEventPublisher, IMessageSource } from '../interfaces'; | ||
|
||
export class DefaultPubSub implements IEventPublisher, IMessageSource { | ||
private subject$: Subject<any>; | ||
export class DefaultPubSub<EventBase extends IEvent> | ||
implements IEventPublisher<EventBase>, IMessageSource<EventBase> { | ||
constructor(private subject$: Subject<EventBase>) {} | ||
|
||
publish<T extends IEvent>(event: T) { | ||
if (!this.subject$) { | ||
throw new Error('Invalid underlying subject (call bridgeEventsTo())'); | ||
} | ||
publish<T extends EventBase>(event: T) { | ||
this.subject$.next(event); | ||
} | ||
|
||
bridgeEventsTo<T extends IEvent>(subject: Subject<T>) { | ||
bridgeEventsTo<T extends EventBase>(subject: Subject<T>) { | ||
this.subject$ = subject; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export interface ICommand {} | ||
export interface ICommand {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { IEvent } from './event.interface'; | ||
|
||
export interface IEventBus { | ||
publish<T extends IEvent>(event: T); | ||
publishAll(events: IEvent[]); | ||
export interface IEventBus<EventBase extends IEvent = IEvent> { | ||
publish<T extends EventBase>(event: T); | ||
publishAll(events: EventBase[]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { IEvent } from './event.interface'; | ||
|
||
export interface IEventPublisher { | ||
publish<T extends IEvent>(event: T); | ||
export interface IEventPublisher<EventBase extends IEvent = IEvent> { | ||
publish<T extends EventBase = EventBase>(event: T); | ||
publishAll?<T extends EventBase = EventBase>(events: T[]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export interface IEvent {} | ||
export interface IEvent {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { Subject } from 'rxjs'; | ||
import { IEvent } from './event.interface'; | ||
|
||
export interface IMessageSource { | ||
bridgeEventsTo<T extends IEvent>(subject: Subject<T>); | ||
export interface IMessageSource<EventBase extends IEvent = IEvent> { | ||
bridgeEventsTo<T extends EventBase>(subject: Subject<T>); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters