1.4.2 • Published 4 years ago

explicit-di v1.4.2

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

explicit-di

Usage:

// composition root file

import { component, systemMap, using } from 'explicit-di'
import { loggerComponent } from '@logger'
import { messagingComponent } from '@messaging'

const componentMap = {
  logger: loggerComponent,
  messaging: using(
    messagingComponent,
    deps: ['logger']
  )
}
// @logger
import { FancyLogger } from 'fancy-logger-tool'
import { component } from 'explicit-di'

const loggerClient = new FancyLogger()

export const loggerComponent = component(() => loggerClient)
// @messaging
import { subscribe } from 'fancy-messaging-tool'
import { ILogger } from '@interfaces'
import { component } from 'explicit-di'

interface Deps {
  logger: ILogger
}

class MessagingClient {
  unsubscribe?: () => {}

  start: ({ logger }: Deps) => {
    logger.logMessage('Start Listening')
    this.unsubscribe = subscribe()
  }

  stop: () => {
    if (this.unsubscribe) this.unsubscribe()
  }
}

const messagingClient = new MessagingClient()

export const messagingComponent = component(
  messagingClient.start,
  messagingClient.stop
)
1.4.2

4 years ago

1.4.1

4 years ago

1.2.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.1.0

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago