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

bindEagerlyTo

Binds injection token to eager dependency.

Importing

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

Type declaration

bindEagerlyTo ::  ContextToken -> ContextReader -> BoundDependency

The function is responsible for binding context token to ContextReader which can be a fp-ts Reader instance or plain sync/async () => T. The function is producing a eager binding, which means that, the dependency will be evaluated on startup.

Example

import { reader, bindEagerlyTo, createContextToken } from '@marblejs/core';
import { createServer } from '@marblejs/http';
import { pipe } from 'fp-ts/lib/function';
import * as R from 'fp-ts/lib/Reader';

// create sync reader

const FooSyncToken = createContextToken<ReturnType<typeof fooSync>>('FooSyncToken');

const fooSync = pipe(reader, R.map(ask => {
  const otherDependency = ask(OtherToken);
  
  return { ... };
});

// create async reader

const FooAsyncToken = createContextToken<ReturnType<typeof fooSync>>('FooSyncToken');

const fooAsync = pipe(reader, R.map(async ask => {
  const otherDependency = ask(OtherToken);
  
  return { ... };
});


// bind readers to tokens

const boundSyncDependency  = bindEagerlyTo(FooSyncToken)(fooSync);
const boundAsyncDependency = bindEagerlyTo(FooAsyncToken)(fooAsync);

PreviousbindToNextcreateEvent

Last updated 3 years ago