Closed aklinker1 closed 1 year ago
I would love to help out!
@tlarkin011 that'd be great, thanks! I'm not a big fan of classes in JS, so this is super low priority for me 😂 That's why I added the "good first issue" and "help wanted" labels lol.
I just created docs to help contributors get started. Let me know if you run into any issues or it doesn't make sense.
https://webext-core.aklinker1.io/guide/contributing.html
Otherwise I'll let you handle it! Thanks again 😄
@aklinker1 Thank you! The docs are great, I will reach out if I have any questions!
@aklinker1 Hello, I may need some help with the specific class updates. Thank you!
@tlarkin011 Are you familiar with function overloading in TypeScript?
All we need to do is add a new override for defineProxyService
that accepts a single argument, and class.
We'll need to replace this:
With something like this:
+export function defineProxyService<TService extends Service, TArgs extends any[]>(
+ classDefinition: { new (...arg: TArgs): TService },
+ config?: ProxyServiceConfig,
+): [registerService: RegisterService<TService, TArgs>, getService: GetService<TService>];
+
export function defineProxyService<TService extends Service, TArgs extends any[]>(
name: string,
init: (...args: TArgs) => TService,
config?: ProxyServiceConfig,
-): [registerService: RegisterService<TService, TArgs>, getService: GetService<TService>] {
+): [registerService: RegisterService<TService, TArgs>, getService: GetService<TService>];
+
+export function defineProxyService<TService extends Service, TArgs extends any[]>(
+ arg1: any,
+ arg2: any,
+ arg3?: any,
+): [registerService: RegisterService<TService, TArgs>, getService: GetService<TService>] {
+ // Based on the overrides, create variables for all the old args
+ const isClassOverride = typeof arg1 !== "string";
+ let name: string = isClassOverride ? arg1.name : arg1;
+ let init: (...args: TArgs) => TService = isClassOverride ? (...args: TArgs) => new arg1(...args) : arg2;
+ let config: ProxyServiceConfig | undefined = isClassOverride ? arg2 : arg3;
+
let service: TService | undefined;
...
@aklinker1 I am familiar with them now. great learning experience! thank you for your help!
No problem, let me know if you have any other questions!
I started on this today, and after some testing, have decided to NOT support a class shorthand.
When an extension is minified, it's name is not unique, and can cause problems.
For a class, you should just be able to pass it into
defineProxyService
without a name or constructor.In this case, it should use the class name for the message, and the constructor when registering it.