Last active
February 11, 2021 18:59
-
-
Save JozefFlakus/876fc23ac0b6b762a2d15d40b0d26525 to your computer and use it in GitHub Desktop.
Marble.js 3.0 - CQRS example
This file contains hidden or 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
// π postOfferFile.effect.ts | |
const postOffersFile$ = r.pipe( | |
r.matchPath('/offers/:id/file'), | |
r.matchType('POST'), | |
r.useEffect((req$, ctx) => { | |
const eventBusClient = useContext(EventBusClientToken)(ctx.ask); | |
return req$.pipe( | |
validateRequest, | |
map(req => req.params.id), | |
tap(id => eventBusClient.emit(OfferCommand.generateOfferFile(id)), | |
mapTo({ status: HttpStatus.ACCEPTED }), | |
); | |
})); | |
// π generateOfferFile.effect.ts | |
const generateOfferFile$: MsgEffect = (event$, ctx) => | |
event$.pipe( | |
matchEvent(GenerateOfferFileCommand), | |
act(eventValidator$(GenerateOfferFileCommand)), | |
act(event => of(event).pipe( | |
map(event => event.payload.offerId), | |
// ... | |
map(id => OfferFileCreatedEvent.create(id)), | |
)), | |
); | |
// π sendOffer.effect.ts | |
const sendOffer$: MsgEffect = (event$, ctx) => | |
event$.pipe( | |
matchEvent(OfferFileCreatedEvent), | |
act(eventValidator$(OfferFileCreatedEvent)), | |
act(event => of(event).pipe( | |
map(event => event.payload.offerId), | |
// ... | |
map(id => OfferSentEvent.create(id)), | |
)), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment