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
fix(TestScheduler): remove applyMixins use #7325
Conversation
In some environments, the `applyMixins` function doesn't work as expected when used with modern JavaScript classes. This was causing issues when code was trying to access `this.logSubscribedFrame` and `this.logUnsubscribedFrame`.
|
||
constructor(public messages: TestMessage[], scheduler: Scheduler) { | ||
super(function (this: Observable<T>, subscriber: Subscriber<any>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this super argument out to just be declared as a method. It's just less complicated.
logSubscribedFrame: () => number; | ||
// @ts-ignore: Property has no initializer and is not definitely assigned | ||
logUnsubscribedFrame: (index: number) => void; | ||
logSubscribedFrame = logSubscribedFrame; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of mixins I'm just adding the methods as function properties on the classes.
constructor(public messages: TestMessage[], scheduler: Scheduler) { | ||
super(function (this: Observable<T>, subscriber: Subscriber<any>) { | ||
const observable: ColdObservable<T> = this as any; | ||
const index = observable.logSubscribedFrame(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In particular, in some environments with CJS and ES2022, applyMixins was not adding the mixing properties to the prototype, and we were getting errors here.
In some environments, the
applyMixins
function doesn't work as expected when used with modern JavaScript classes. This was causing issues when code was trying to accessthis.logSubscribedFrame
andthis.logUnsubscribedFrame
.This didn't appear until we switched over to ES2022 in CJS exports, and it doesn't appear to be an issue in all runtimes. In any case, simplifying the code solved the issue. Tested against some live tests in another repo, I don't have a solid way to duplicate it here. It's sort of a fluke/one-off.