LogoLogo
ChangelogGitHubTwitterGitter
v3.x
v3.x
  • Marble.js
  • Getting started
    • Installation
    • Quick setup
  • HTTP
    • Effects
    • Middlewares
    • Routing
    • Errors
    • Output
    • Context
    • Advanced
      • Logging
      • Validation
      • Server Events
      • Streaming
      • Continuous mode
  • Messaging
    • Core concepts
      • Events
      • Effects
    • Microservices
      • AMQP (RabbitMQ)
      • Redis Pub/Sub
    • CQRS
    • WebSockets
  • Testing
    • HTTP routes testing
  • Other
    • How does it glue together?
    • Migration guides
      • Migration from version 2.x
      • Migration from version 1.x
    • API reference
      • core
        • bindTo
        • bindEagerlyTo
        • createEvent
        • createServer
        • combineRoutes
        • createContextToken
        • EffectFactory
        • r.pipe
        • httpListener
        • operator: matchEvent
        • operator: use
        • operator: act
      • messaging
        • eventBus
        • messagingClient
        • createMicroservice
        • reply
      • websockets
        • webSocketListener
        • operator: broadcast
        • operator: mapToServer
      • middleware-multipart
      • middleware-cors
      • middleware-joi
      • middleware-jwt
        • Token signing
      • middleware-io
      • middleware-logger
      • middleware-body
    • Style Guide
    • FAQ
Powered by GitBook
On this page
  • Importing
  • Type declaration
  • Example
  1. Other
  2. API reference
  3. core

operator: matchEvent

Effect operator for matching incoming events.

Importing

import { matchEvent } from '@marblejs/core';

Type declaration

matchEvent :: (EventLike | EventCreator) -> Observable<Event> -> Observable<Event>

Example

WsEffect:

import { matchEvent } from '@marblejs/core';
import { WsEffect } from '@marblejs/websockets';
import { map } from 'rxjs/operators';

const add$: WsEffect = event$ =>
  event$.pipe(
    matchEvent('ADD'),
    map(event => event.payload), // (typeof payload) = unknown
    // ...
  );

HttpServerEffect:

import { matchEvent, HttpServerEffect, ServerEvent } from '@marblejs/core';
import { map } from 'rxjs/operators';

const listening$: HttpServerEffect = event$ =>
  event$.pipe(
    matchEvent(ServerEvent.listening),
    map(event => event.payload), // (typeof payload) = { port: number; host: string; }
    // ...
  );

MsgEffect:

import { matchEvent, createEvent, EventsUnion } from '@marblejs/core';
import { MsgEffect } from '@marblejs/messaging';
import { map } from 'rxjs/operators';

// Commands definition

export enum AddCommandType {
  ADD = 'ADD',
};

export const AddCommand = {
  add: createEvent(
    AddCommandType.ADD,
    (val: number) => ({ val }),
  ),
};

export type AddCommand = EventsUnion<typeof AddCommand>;

// Effect definition

const add$: MsgEffect = event$ =>
  event$.pipe(
    matchEvent(AddCommand.add),
    map(event => event.payload), // (typeof payload) = { val: number };
    // ...
  );
PrevioushttpListenerNextoperator: use

Last updated 5 years ago