This package has been deprecated

Author message:

@ragg/fleur-di is deprecated, use @fleur/di instead

@ragg/fleur-di
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

🌼 fleur-di 💉 npm version travis

Simply DI container without any dependency for TypeScript

Example

import { inject } from '@ragg/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'))

Readme

Keywords

none

Package Sidebar

Install

npm i @ragg/fleur-di

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

2.39 kB

Total Files

7

Last publish

Collaborators

  • ragg