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

Awilix V6 #272

Merged
merged 7 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: node_js
node_js:
- 'stable'
# Disabling Stable for now since there's some breakage in tslib
# on Node 17.
# - 'stable'
- '16'
- '14'
- '12'
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# v6.0.0

Please see the list of breaking changes below.

- Update packages
- **BREAKING**: [#198](https://github.com/jeffijoe/awilix/issues/198) Don't parse parameters from base class
- [#270](https://github.com/jeffijoe/awilix/issues/270) Fix exponential performance slowdown for large containers
- This was done by not relying on `rollUpRegistrations` in the `resolve` path. As a trade-off, performance
for iterating the `cradle` proxy has degraded in order to guarantee accuracy. We consider this acceptable as iterating
the `cradle` is not something one should be doing for anything besides debugging. Thanks to [@code-ape](https://github.com/code-ape)
for the diagnosis and for coming up with a fix!

### BREAKING CHANGES

* The `container.registrations` getter on a scoped container no longer rolls up registrations from its' parent.
* In `CLASSIC` mode, when parsing the constructor of a derived class, Awilix will no longer parse the base class' constructor in
case the derived class' defined constructor does not define any arguments. However, if the derived class does _not_ define a constructor,
then Awilix will parse the base class' constructor. Please keep in mind that this only works for native classes, as Awilix works on the
`toString` representation of the class/function in order to determine when a class with no defined constructor is encountered.
* Renamed `container.has` to `container.hasRegistration` to avoid ambiguity. _Does it have a registration? Does it have a cached module? Who knows? Let's gooo!_

# v5.0.1

- Improve internal `uniq` function performance by using a `Set` ([#253](https://github.com/jeffijoe/awilix/pull/253), [Anderson Leite](https://github.com/andersonleite))
Expand Down
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ written in [TypeScript](http://typescriptlang.org). **Make IoC great again!**
- [`container.build()`](#containerbuild)
- [`container.dispose()`](#containerdispose)
- [Universal Module (Browser Support)](#universal-module-browser-support)
- [Contributing](#contributing)
- [Contributing](#contributing)
- [What's in a name?](#whats-in-a-name)
- [Author](#author)

Expand Down Expand Up @@ -351,8 +351,12 @@ modes are available on `awilix.InjectionMode`
```

- `InjectionMode.CLASSIC`: Parses the function/constructor parameters, and
matches them with registrations in the container. _Don't use this if you
minify your code!_
matches them with registrations in the container. `CLASSIC` mode has a
slightly higher initialization cost as it has to parse the function/class
to figure out the dependencies at the time of registration, however resolving
them will be **much faster** than when using `PROXY`. _Don't use `CLASSIC` if
you minify your code!_ We recommend using `CLASSIC` in Node and `PROXY` in
environments where minification is needed.

```js
class UserService {
Expand All @@ -363,7 +367,8 @@ modes are available on `awilix.InjectionMode`
}
```

Additionally, if the class has a base class but does not report any dependencies, the base class dependencies are passed in.
Additionally, if the class has a base class but does not declare a constructor of its own, Awilix
simply invokes the base constructor with whatever dependencies it requires.

```js
class Car {
Expand All @@ -373,9 +378,8 @@ modes are available on `awilix.InjectionMode`
}

class Porsche extends Car {
constructor() {
super(...arguments)
console.log(arguments[0]) // whatever "engine" is
vroom() {
console.log(this.engine) // whatever "engine" is
}
}
```
Expand Down Expand Up @@ -1064,7 +1068,8 @@ Args:
pass the name through as-is. The 2nd parameter is a full module descriptor.
- `opts.resolverOptions`: An `object` passed to the resolvers. Used to configure
the lifetime, injection mode and more of the loaded modules.
- `opts.esModules`: Loads modules using Node's native ES modules. This is only supported on Node 14.0+ and should only be used if you're using the [Native Node ES modules](https://nodejs.org/api/esm.html)
- `opts.esModules`: Loads modules using Node's native ES modules. This is only
supported on Node 14.0+ and should only be used if you're using the [Native Node ES modules](https://nodejs.org/api/esm.html)

Example:

Expand Down