Skip to content

Instantly share code, notes, and snippets.

View JozefFlakus's full-sized avatar
💭
λ

Józef Flakus JozefFlakus

💭
λ
View GitHub Profile
export const server = createServer({
port: 1337,
httpListener,
dependencies: [
bindTo(WsServerToken)(webSocketListener().run),
],
});
// ...
import { use, r } from '@marblejs/core';
const postUser$ = r.pipe(
r.matchPath('/'),
r.matchType('POST'),
r.use(authorize$),
r.useEffect(req$ => req$.pipe(
use(postUserValidator$),
map(req => req.body),
mergeMap(createUser),
import { use, matchEvent } from '@marblejs/core';
import { WsEffect } from '@marblejs/websockets';
import { t, eventValidator$ } from '@marblejs/middleware-io';
export const sum$: WsEffect = event$ =>
event$.pipe(
matchEvent('SUM')
);
export const add$: WsEffect = (event$, ...args) =>
@JozefFlakus
JozefFlakus / auth.middleware.ts
Last active August 28, 2018 20:50
Marble.js - Example middleware
export const authorize$: Middleware = (req$) =>
req$.pipe(
switchMap(req => iif(
() => !isAuthorized(req),
throwError(new HttpError('Unauthorized', HttpStatus.UNAUTHORIZED)),
of(req),
)),
);
const effect$: Effect = (req$) =>
req$.pipe(
// ...
);
const middleware$: Middleware = (req$, res) =>
req$.pipe(
// ...
);
@JozefFlakus
JozefFlakus / user.controller.ts
Created August 28, 2018 20:38
Marble.js - sample controller example
const getUsers$ = EffectFactory
.matchPath('/')
.matchType('GET')
.use(req$ => req$.pipe(
switchMap(Dao.getUsers),
map(users => ({ body: users })),
));
const postUser$ = EffectFactory
.matchPath('/')