Socket
Book a DemoInstallSign in
Socket

@fleur/di

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fleur/di

Simply DI container without any dependency for TypeScript

latest
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

🌼 fleur-di 💉 npm version travis

Simply DI container without any dependency for TypeScript

Example

import { inject } from '@fleur/di'
import { getUser } from './api'

const fetchUser = inject({ getUser })(
  (injects) => async (userId: string) => {
    await injects.getUser(userId)
  },
)

// Fetch user data
await fetchUser('1')

// Inject mock
const getUserMock = async (userId: string) => ({ id: userId })
await fetchUser.inject({ getUser: getUserMock }).exec('1')

// with redux-thunk
export const fetchUserAction = inject({ getUser })(
  (injects) => (userId: string) => async (dispatch, getState) => {
    const user = await injects.getUser(userId)
    dispatch({ type: 'FETCH_USER_SUCCESS', payload: user })
  },
)

// in tests
dispatch(fetchUserAction.inject({ getUser: getUserMock }).exec('1'))

FAQs

Package last updated on 21 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts