1.0.2 • Published 5 years ago

@ragg/fleur-di v1.0.2

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

🌼 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'))
1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-pre

5 years ago