-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TS decorator support and replace class arrow function fields with…
… bound methods (#790) * merge cherry-pick * merge cherry-pick decorators * clarify vite usage * Create lovely-crabs-hide.md * prettier decorators * prettier * improve types * more field to method conversion * use ts preset and preset-env for vite babel * fix merge
- Loading branch information
Showing
19 changed files
with
810 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"livekit-client": patch | ||
--- | ||
|
||
Add TS decorator support and replace class arrow function properties with bound methods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* ensure that the method isn’t re-bound if it is called as a stand-alone function or passed as a callback. | ||
* @see https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#decorators | ||
*/ | ||
export function bound<T extends Object>( | ||
_originalMethod: Function, | ||
context: ClassMethodDecoratorContext<T>, | ||
) { | ||
const methodName = context.name as keyof T; | ||
if (context.private) { | ||
throw new Error(`'bound' cannot decorate private properties like ${methodName as string}.`); | ||
} | ||
|
||
context.addInitializer(function () { | ||
this[methodName] = (this[methodName] as Function).bind(this); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.