joist-framework / joist

A small (~2kb) library to help with the creation of web components and web component based applications
121 stars 6 forks source link

Injectable Services have their Constructor wrapped, arguments are not delegated #1071

Closed Phoscur closed 1 month ago

Phoscur commented 1 month ago

Describe the bug Maybe this should be a feature request, I have probably overlooked a hint in the docs...

To Reproduce, run:

import { injectable } from '@joist/di';

@injectable
class Service {
  constructor(str = 'a') {
    console.log(str);
  }
}
new Service('b');

Expected behavior Should print 'b' - forwarding the argument to the orignal constructor Prints 'a' instead (both v3 & v4.next11)

Additional context I found hints for constructor usage near the docs for provider factory usage. It would be helpful to be able to also use different constructor arguments for decorated services!

deebloo commented 1 month ago

Ummmmm let me check on that. It definitely should forward those on. Should be a pretty small fix if you want to take a look at the injectable decorator.

https://github.com/joist-framework/joist/blob/main/packages/di/src/lib/injectable.ts#L18

Phoscur commented 1 month ago

Yes just found that, shall I submit a fix with a test?

deebloo commented 1 month ago

Yes just found that, shall I submit a fix with a test?

Please do! Will be happy to review :)

Phoscur commented 1 month ago

Nice, when can I expect new versions? @deebloo

Sidenote concerning unit tests: Why the switch from expect to assert, while chai actually supports both?

deebloo commented 1 month ago

Sometimes today. Right now it's time for football :). And no real reason. I prefer assert and it is also the format that the native node assert module uses.

deebloo commented 1 month ago

@Phoscur new releases cut for both 4.0 and 3.0

Phoscur commented 1 month ago

Nice, I'm on 3.9.2 now and it's fixed! Should I consider upgrading to v4 asap?

deebloo commented 1 month ago

Up to you. The di package is really stable. No more changes unless bugs are found.