npm.io
1.1.2 • Published 1 month ago

@wendellhu/redi

Licence
MIT
Version
1.1.2
Deps
0
Size
586 kB
Vulns
0
Weekly
0
Stars
168

redi

stars downloads license coverage

redi (pronounced 'ready') is a lightweight dependency injection library for TypeScript and JavaScript, with React bindings included.

Why redi?

Feature Description
Lightweight Zero dependencies, small bundle size
esbuild friendly No emitDecoratorMetadata required
Feature-rich Class, value, factory, async injection and more
React ready Built-in hooks for React integration
Well tested 100% code coverage

Quick Start

npm install @wendellhu/redi
import { Inject, Injector } from '@wendellhu/redi';

class AuthService {
  getCurrentUserInfo(): UserInfo {
    /* ... */
  }
}

class FileListService {
  constructor(@Inject(AuthService) private authService: AuthService) {}

  getUserFiles(): Promise<Files> {
    const user = this.authService.getCurrentUserInfo();
    // ...
  }
}

const injector = new Injector([[AuthService], [FileListService]]);
const fileList = injector.get(FileListService);

Getting started.

Features

Who's Using redi?

License

MIT. Copyright 2021-present Wenzhao Hu.