How to use the @marblejs/core.matchEvent function in @marblejs/core

To help you get started, we’ve selected a few @marblejs/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marblejs / marble / packages / @integration / src / messaging / client.ts View on Github external
const listening$: HttpServerEffect = event$ =>
  event$.pipe(
    matchEvent(ServerEvent.listening),
    map(event => event.payload),
    tap(({ port, host }) => console.log(`Server running @ http://${host}:${port}/ 🚀`)),
  );
github marblejs / marble / packages / @integration / src / websockets / http.server.ts View on Github external
const listening$: HttpServerEffect = event$ =>
  event$.pipe(
    matchEvent(ServerEvent.listening),
    map(event => event.payload),
    tap(({ port, host }) => console.log(`Server running @ http://${host}:${port}/ 🚀`)),
  );
github marblejs / marble / packages / messaging / src / server / specs / messaging.server.redis.spec.ts View on Github external
const event$: MsgEffect = event$ =>
      event$.pipe(
        matchEvent('EVENT_TEST'),
        use(eventValidator$(t.number)),
        map(event => event.payload),
        map(payload => ({ type: 'EVENT_TEST_RESPONSE', payload: payload + 1 })),
        tap(async event => {
          expect(event).toEqual({ type: 'EVENT_TEST_RESPONSE', payload: 2 });
          await wait();
          await server.close();
          await client.close();
          done();
        }),
      );
github marblejs / marble / packages / @integration / src / effects / calculator.ws-effects.ts View on Github external
export const add$: WsEffect = (event$, ...args) =>
  event$.pipe(
    matchEvent('ADD'),
    use(eventValidator$(t.number)),
    buffer(sum$(event$, ...args)),
    map(addEvents => addEvents.reduce((a, e) => e.payload + a, 0)),
    map(payload => ({ type: 'SUM_RESULT', payload })),
  );
github marblejs / marble / packages / @integration / src / websockets / websockets.server.ts View on Github external
const add$: WsEffect = (event$, ...args) =>
  event$.pipe(
    matchEvent('ADD'),
    use(eventValidator$(t.number)),
    buffer(sum$(event$, ...args)),
    map(addEvents => addEvents.reduce((a, e) => e.payload + a, 0)),
    map(payload => ({ type: 'SUM_RESULT', payload })),
  );
github marblejs / marble / packages / messaging / src / server / specs / messaging.server.amqp.spec.ts View on Github external
const event1$: MsgEffect = event$ =>
      event$.pipe(
        matchEvent(event1.type),
        mergeMapTo(throwError(error)),
      );
github marblejs / marble / packages / messaging / src / client / messaging.client.ts View on Github external
const teardownOnClose$ = (conn: Promise) => (event$: Observable) =>
    event$.pipe(
      matchEvent(ServerEvent.close),
      take(1),
      mergeMapTo(conn),
      mergeMap(conn => conn.close()),
    );
github marblejs / marble / packages / messaging / src / middlewares / messaging.statusLogger.middleware.ts View on Github external
const connect$: MsgServerEffect = (event$, ctx) => {
  const logger = provideLogger(ctx.ask);
  const transportLayer = useContext(TransportLayerToken)(ctx.ask);

  return event$.pipe(
    matchEvent(ServerEvent.status),
    map(event => event.payload),
    distinctUntilChanged((p, c) => p.type === c.type),
    filter(({ type }) => type === serverStatusMap.connect[transportLayer.type]),
    tap(({ host, channel }) => logger({
      tag: 'CONNECTED',
      message: `Connected server to host: ${host}`,
      level: LoggerLevel.INFO,
      channel,
    })),
  );
};
github marblejs / marble / packages / messaging / src / middlewares / messaging.statusLogger.middleware.ts View on Github external
const error$: MsgServerEffect = (event$, ctx) => {
  const logger = provideLogger(ctx.ask);
  const transportLayer = useContext(TransportLayerToken)(ctx.ask);

  return event$.pipe(
    matchEvent(ServerEvent.error),
    map(event => event.payload),
    tap(({ error }) => logger({
      tag: 'ERROR',
      message: `${error.name}, ${error.message}`,
      level: LoggerLevel.ERROR,
      channel: transportLayer.config.channel,
    }))
  );
};
github marblejs / marble / packages / @integration / src / effects / calculator.ws-effects.ts View on Github external
export const sum$: WsEffect = event$ =>
  event$.pipe(
    matchEvent('SUM')
  );