LogoLogo
ChangelogGitHubTwitterGitter
v4.x
v4.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 3.x
      • Migration from version 2.x
      • Migration from version 1.x
    • API reference
      • @marblejs/core
        • bindTo
        • bindEagerlyTo
        • createEvent
        • createContextToken
        • operator: matchEvent
        • operator: use
        • operator: act
      • @marblejs/http
        • httpListener
        • r.pipe
        • combineRoutes
        • createServer
      • @marblejs/messaging
        • eventBus
        • messagingClient
        • createMicroservice
        • reply
      • @marblejs/websockets
        • webSocketListener
        • operator: broadcast
        • operator: mapToServer
      • @marblejs/middleware-multipart
      • @marblejs/middleware-cors
      • @marblejs/middleware-io
      • @marblejs/middleware-logger
      • @marblejs/middleware-body
      • @marblejs-contrib/middleware-jwt
        • Token signing
      • @marblejs-contrib/middleware-joi
    • Style Guide
    • FAQ
Powered by GitBook
On this page
  • Importing
  • Type declaration
  • Example
  1. Other
  2. API reference
  3. @marblejs/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 } from '@marblejs/core';
import { HttpServerEffect, ServerEvent } from '@marblejs/http';
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, event, EventsUnion } from '@marblejs/core';
import { MsgEffect } from '@marblejs/messaging';
import * as t from 'io-ts';
import { map } from 'rxjs/operators';

// Commands definition

export enum OfferCommandType {
  GENERATE_OFFER_DOCUMENT = 'GENERATE_OFFER_DOCUMENT',
}

export const GenerateOfferDocumentCommand =
  event(OfferCommandType.GENERATE_OFFER_DOCUMENT)(t.type({ offerId: t.string }));

// Effect definition

const generateOfferDocument$: MsgEffect = event$ =>
  event$.pipe(
    matchEvent(GenerateOfferDocumentCommand),
    map(event => event.payload), // (typeof payload) = { offerId: string };
    // ...
  );
PreviouscreateContextTokenNextoperator: use

Last updated 3 years ago