Created
February 1, 2024 07:50
-
-
Save kalysr/ef1cb61946c828c4106059b613124283 to your computer and use it in GitHub Desktop.
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
class Consumer<R> { | |
subscribe<T extends abstract new (...args: any) => any>(event: T, map: (event: InstanceType<T>) => R): Consumer<R> { | |
return this; | |
} | |
connect(): Consumer<R> { | |
return this; | |
} | |
handle(handler: (event: R) => any): Consumer<R> { | |
//asdasa | |
return this; | |
} | |
} | |
const consumer = new Consumer<{ guid: string }>() | |
.subscribe(PaymentOrderEvents.Created, ({ guid }) => ({ guid })) | |
.subscribe(PaymentOrderEvents.Processing, ({ guid }) => ({ guid })) | |
.subscribe(PaymentOrderEvents.Completed, ({ guid }) => ({ guid })) | |
.subscribe(PaymentOrderEvents.Canceled, ({ guid }) => ({ guid })) | |
.subscribe(PaymentOrderEvents.Failed, ({ guid }) => ({ guid })) | |
.subscribe(PaymentOrderEvents.Expired, ({ guid }) => ({ guid })) | |
.subscribe(PaymentOrderEvents.Expired, ({ guid }) => ({ guid })) | |
.connect() | |
.handle(({ guid }) => { | |
console.log({ guid }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment