Giter Club home page Giter Club logo

redi's Introduction

redi

Stars Downloads License Codecov

A dependency library for TypeScript and JavaScript, along with a binding for React.

Overview

import { Inject } from '@wendellhu/redi'

class AuthService {
    public getCurrentUserInfo(): UserInfo {}
}

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

    public getUserFiles(): Promise<Files> {
        const currentUser = this.authService.getCurrentUserInfo()
    }
}

const injector = new Injector([[AuthService], [FileListService]])

injector.get(AuthService)

View full documentation on redi.wendell.fun.

Links

Users

  • Univer
  • Team Lark at ByteDance

License

MIT. Copyright 2021-present Wenzhao Hu.

redi's People

Contributors

bailnl avatar wzhudev avatar xiaofei-2020 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

redi's Issues

循环依赖问题的解决方案有 bug

检查循环依赖的实现方案感觉有 bug ?因为如果 _resolveClass 方法实例化次数确实大于等于 MAX_RESOLUTIONS_QUEUED 次呢,当然这种情况实际上几乎可能不会有,但是就是不考虑这种情况,那么该实现方案在解决循环依赖问题的本质上也不应该是记录 _resolveClass 方法被调用的次数。通过认为正常情况 _resolveClass 方法被调用不可能大于 MAX_RESOLUTIONS_QUEUED 定义的 300 次来侧面判断循环依赖问题,我认为是有缺陷的,没有严谨的解决该问题。

装饰器--babel兼容typescript的解决方案

文档上说:需要保证是由 TypeScript 对你的源码进行翻译而不是 Babel,但没有给出babel的兼容方案
image

目前项目使用的babel编译,无法直接换成Typescript编译。

最终在babel社区找到,babel兼容typescript的可行方案。

{ "presets": [ ["@babel/preset-typescript"] ], "plugins": [ ["babel-plugin-transform-typescript-metadata", {}], ["@babel/plugin-proposal-decorators", {version: 'legacy'}], ["@babel/plugin-transform-typescript", {}] ] }

关键是babel-plugin-transform-typescript-metadata

在此记录一下,以供大家参考。

Feature request: `WithNew()` with parameters

当依赖项为工厂函数时,如果可以让 WithNew() 带参数传入工厂函数是有用的:

export class MyService {
  constructor(
    @WithNew(MyService.name)
    @Inject(LoggerService)
    private readonly loggerService: LoggerService
  ) {}

  foo() {
    this.loggerService.info('bar');
  }
}

useFactory: (name: string) => {
  return new LoggerService(name);
}

export class LoggerService {
  constructor(private readonly name: string) {}

  info(message: string) {
    console.info(`${this.name} ${message}`);
  }
}

上面的例子就使用了 WithNew() 里面的参数传入给工厂函数,相当于要求 DI 注入的服务具有某种规格。

具体的设计还有待商榷,如果此提议有效,很乐意帮忙提供 PR 😄

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.