Skip to content

Commit

Permalink
Added more description about the event process
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Feb 10, 2024
1 parent 2c5f289 commit dde38cf
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 28 deletions.
21 changes: 21 additions & 0 deletions docs/snippets/api/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
// #region event-type
import type { Event } from '@event-driven-io/emmett';

type ProductItemAddedToShoppingCart = Event<
'ProductItemAddedToShoppingCart',
{
shoppingCartId: string;
productItem: PricedProductItem;
}
>;
// #endregion event-type

export interface ProductItem {
productId: string;
quantity: number;
}

export type PricedProductItem = ProductItem & {
price: number;
};
65 changes: 37 additions & 28 deletions docs/snippets/shoppingCart.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
// #region getting-started-events
import type { Event } from '@event-driven-io/emmett';

type ProductItemAddedToShoppingCart = Event<
'ProductItemAddedToShoppingCart',
{
shoppingCartId: string;
productItem: PricedProductItem;
}
>;

type ProductItemRemovedFromShoppingCart = Event<
'ProductItemRemovedFromShoppingCart',
{
shoppingCartId: string;
productItem: PricedProductItem;
}
>;

type ShoppingCartConfirmed = Event<
'ShoppingCartConfirmed',
{
shoppingCartId: string;
confirmedAt: Date;
}
>;

type ShoppingCartCanceled = Event<
'ShoppingCartCanceled',
{
shoppingCartId: string;
canceledAt: Date;
}
>;

export type ShoppingCartEvent =
| {
type: 'ProductItemAddedToShoppingCart';
data: {
shoppingCartId: string;
productItem: PricedProductItem;
};
}
| {
type: 'ProductItemRemovedFromShoppingCart';
data: {
shoppingCartId: string;
productItem: PricedProductItem;
};
}
| {
type: 'ShoppingCartConfirmed';
data: {
shoppingCartId: string;
confirmedAt: Date;
};
}
| {
type: 'ShoppingCartCanceled';
data: {
shoppingCartId: string;
canceledAt: Date;
};
};
| ProductItemAddedToShoppingCart
| ProductItemRemovedFromShoppingCart
| ShoppingCartConfirmed
| ShoppingCartCanceled;

export interface ProductItem {
productId: string;
Expand Down

0 comments on commit dde38cf

Please sign in to comment.