Skip to content

Instantly share code, notes, and snippets.

View JozefFlakus's full-sized avatar
馃挱

J贸zef Flakus JozefFlakus

馃挱
View GitHub Profile
@JozefFlakus
JozefFlakus / microservice.ts
Last active February 11, 2021 19:01
Marble.js 3.0 - microservice example
// 馃搫 publisher - fib.effect.ts
const fib$ = r.pipe(
r.matchPath('/fib/:number'),
r.matchType('GET'),
r.useEffect((req$, ctx) => {
const client = useContext(ClientToken)(ctx.ask);
return req$.pipe(
validateRequest,
@JozefFlakus
JozefFlakus / continuous-http-streams.ts
Last active January 31, 2020 19:09
Marble.js 3.0 - continuous streams
const foo$ = r.pipe(
r.applyMeta({ continuous: true }),
r.matchPath('/'),
r.matchType('GET'),
r.useEffect((req$, ctx) => {
const reqBus$ = useContext(HttpRequestBusToken)(ctx.ask);
const terminate$ = reqBus$.pipe(filter(req => req.url === '/flush'));
return req$.pipe(
bufferWhen(() => terminate$),
@JozefFlakus
JozefFlakus / async-readers.ts
Last active February 1, 2020 22:28
Marble.js 3.0 - async readers
bindEagerlyTo(Token)(async () => 'bar');
const foo = useContext(Token)(ask); // foo === 'bar'
// but...
bindTo(Token)(async () => 'bar');
const foo = useContext(Token)(ask); // foo === Promise<'bar'>
@JozefFlakus
JozefFlakus / logging.ts
Last active January 27, 2020 22:05
Marble.js 3.0 - default logging
// HTTP server logger output
位 - 47700 - 2020-01-27 22:04:21 - http [Context] - Registered: "HttpRequestBusToken"
位 - 47700 - 2020-01-27 22:04:21 - http [Context] - Registered: "HttpServerClientToken"
位 - 47700 - 2020-01-27 22:04:21 - http [Context] - Registered: "HttpServerEventStreamToken"
位 - 47700 - 2020-01-27 22:04:21 - http [Context] - Registered: "LoggerToken"
位 - 47700 - 2020-01-27 22:04:21 - http [Router] - Effect mapped: /api/:version GET
位 - 47700 - 2020-01-27 22:04:21 - http [Router] - Effect mapped: /api/:version/user GET
位 - 47700 - 2020-01-27 22:04:21 - http [Router] - Effect mapped: /api/:version/user POST
位 - 47700 - 2020-01-27 22:04:21 - http [Router] - Effect mapped: /api/:version/user/:id GET
@JozefFlakus
JozefFlakus / effect.ts
Last active February 6, 2020 08:06
Marble.js 3.0 - effect interface
interface Effect<I, O, Client> {
(input$: Observable<I>, ctx: EffectContext<Client>): Observable<O>;
}
interface HttpEffect<
I = HttpRequest,
O = HttpEffectResponse,
> extends Effect<I, O, HttpServer> {}
interface WsEffect<
@JozefFlakus
JozefFlakus / cqrs.ts
Last active February 11, 2021 18:59
Marble.js 3.0 - CQRS example
// 馃搫 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,