Skip to content

Instantly share code, notes, and snippets.

@kalysr
Created February 1, 2024 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalysr/ef1cb61946c828c4106059b613124283 to your computer and use it in GitHub Desktop.
Save kalysr/ef1cb61946c828c4106059b613124283 to your computer and use it in GitHub Desktop.
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