Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find replacement for DI #2475

Open
dignifiedquire opened this issue Nov 28, 2016 · 11 comments
Open

Find replacement for DI #2475

dignifiedquire opened this issue Nov 28, 2016 · 11 comments

Comments

@dignifiedquire
Copy link
Member

dignifiedquire commented Nov 28, 2016

The di (dependency injection) module we currently use is very outdated and the di setup we have is pretty hard to understand, especially for people new to the code base.

Currently all plugins though depend on it, so we need to find a backwards compatible solution or at least an interface that is as simple to use as the current one for plugin authors.

@dignifiedquire dignifiedquire changed the title [refactor] Find replacement for DI Find replacement for DI Nov 28, 2016
@maksimr
Copy link
Contributor

maksimr commented Nov 29, 2016

IMHO

I really like idea of dependency injection(DI) :neckbeard: .
Only one thing in karma's DI like a magic. It is DI using comment in function's argument:

fooReporter(/*config.client*/client) { return client }

@dignifiedquire why do you want replace it? Only because people can not understand it?
Really they don't understand it or maybe we could improve DI's API make it more obvious if it's not ovious now

✌️

@dignifiedquire
Copy link
Member Author

@maksimr I am not sure, maybe just update things to use a newer library. If we are happy with DI itself I am happy to just move to a maintained library.

@EzraBrooks
Copy link
Collaborator

After doing a short review of how often we actually use di, it seems like it's not really a requirement for the project and could probably be refactored out. I think refactoring it out would make the whole application be less "magic" and probably help with static analysis (via tools like TypeScript).

@EzraBrooks
Copy link
Collaborator

Main issue is, as you said, refactoring it out of Karma without breaking things for plugin authors.

@EzraBrooks
Copy link
Collaborator

@dignifiedquire would you be open to a PR utilizing injection-js? Could also combine that feature with moving from pseudo-classes to proper ECMAScript classes, since that should make injection easier. Currently my TypeScript PR (#2893) is blocked by a bunch of ambiguous typing that is a result of pseudo-classing making things unclear.

@johnjbarton
Copy link
Contributor

I'm curious about your definition of pseudo-classes. Are you talking about code like url

Url.prototype.toString = function () {

which defines methods on .prototype (should be converted to es6 classes) or like dots
this.onBrowserStart = function (browser) {
where methods are defined directly on the objects (where changes may have broader consequences)?

Or both ;-)

@EzraBrooks
Copy link
Collaborator

Both, although the former is more egregious. I was wrestling with type ambiguity in file-list the other night and the easiest solution was rewriting the whole thing as an ES6 class.

@dignifiedquire
Copy link
Member Author

  • I would love to see the code base upgraded to use class, const, let and arrow functions.
  • I am very open to use a different di library, as long as we can keep all existing plugins compatible. There are a lot of plugins out there, from various authors which rely on the current workings to work. Maintained + tested is the base requirement. But I would like to stay away from compiling things, so ideally using the regular es6 version, no typescript class annotations

@johnjbarton
Copy link
Contributor

I suggest tackling es6 and new DI separately, starting with a simple case, and developing a documented recipe for these changes. I guess the test coverage for the plugin space is not sufficient to ensure that a passing karma test will ensure plugins work. So patience and documentation will be essential.

@EzraBrooks
Copy link
Collaborator

Does the old DI work with new class syntax? My concern is that rewriting them separately might raise unexpected compatibility issues and it might just be best to make any breaking changes simultaneously instead of in multiple steps.

@johnjbarton
Copy link
Contributor

es6 classes can be used with es3 code; it may or may not be pretty and some investigation may be needed.

Changing the DI is, I believe, a much bigger issue because it is part of how plugins interface with karma. We would need some kind of migration strategy where old and new DI are both allowed, then we reach-out/DIY the changes for the top plugins, then deprecate the old DI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants