Skip to content
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

Merged
merged 1 commit into from Aug 19, 2023

Conversation

benlesh
Copy link
Member

@benlesh benlesh commented Aug 19, 2023

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.

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.

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>) {
Copy link
Member Author

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;
Copy link
Member Author

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();
Copy link
Member Author

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.

@benlesh benlesh merged commit e01d3c1 into ReactiveX:master Aug 19, 2023
3 checks passed
@benlesh benlesh deleted the refactor-remove-applyMixin branch August 19, 2023 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants