0.1.0 • Published 8 months ago

hook-di v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

hook-di

Reconsidering dependencies injection in hook style programming.

Highly inspired by vue composition apis.

usage

here is the interfaces

import { InjectionKey } from 'hook-di'

export interface MyService {
  hello: () => string
}
// InjectionKey
export const MyServiceKey: InjectionKey<MyService> = InjectionKey('my-service')

// use MyService hook
export function useMyService(): MyService {
  return {
    hello() {
      return `storea`
    },
  }
}

manually register dependencies and auto inject.

import { createScope, use } from '../src'

const scope = createScope()
scope.register(MyServiceKey, useMyService)

scope.run(() => {
  const service = use(MyServiceKey)
  service.hello() // "storebstorea"
})
0.1.0

8 months ago

0.0.14

3 years ago

0.0.15

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago