Open
Conversation
b3c71f9 to
ed03667
Compare
Convert public arrow function class fields back to regular prototype methods and wrap them with `deprecatedBoundMethods` in the constructor for backwards compatibility. When a method is called with a lost `this` (e.g. via destructuring), a per-method deprecation warning is emitted once. In the next major the wrappers will be removed and unbound calls will fail. Closes keycloak#300 Signed-off-by: Jon Koops <[email protected]>
ed03667 to
1d0e84c
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR converts public arrow function class fields on the
Keycloakclass back to regular prototype methods and introduces adeprecatedBoundMethodshelper that wraps them in the constructor for backwards compatibility.When a method is called with a lost
thiscontext (e.g. via destructuring likeconst { login } = keycloak; login()), a per-method deprecation warning is emitted once in the console. The methods continue to work correctly in the meantime. In the next major version, the wrappers will be removed and unbound calls will fail, which is the standard behavior for class methods.The arrow function class fields were introduced in #204 to fix destructuring, but they come with downsides: no prototype sharing (increased memory per instance), no reference equality across instances, and broken subclassing. This change restores proper prototype methods while giving consumers time to migrate away from destructuring patterns.
Closes #300