Skip to content

useObserver registry refactor - #3598

Merged
urugator merged 6 commits into
mainfrom
registry-refactor
Jan 14, 2023
Merged

useObserver registry refactor#3598
urugator merged 6 commits into
mainfrom
registry-refactor

Conversation

@urugator

Copy link
Copy Markdown
Collaborator

As discussed here #3590 (comment)

@changeset-bot

changeset-bot Bot commented Dec 31, 2022

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b6e7128

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mobx-react-lite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mweststrate mweststrate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, thanks for putting that in a separate PR!

@Bnaya Bnaya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

less code = It's better :D

throw new Error("This test must run with node >= 14")
}

expect(observerFinalizationRegistry).toBeInstanceOf(globalThis.FinalizationRegistry)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it do if it fails? it's not inside any test

import { observerFinalizationRegistry } from "../src/utils/observerFinalizationRegistry"
import { TimerBasedFinalizationRegistry } from "../src/utils/UniversalFinalizationRegistry"

expect(observerFinalizationRegistry).toBeInstanceOf(TimerBasedFinalizationRegistry)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it do if it fails?

Throws?

it's not inside any test

Does it matter?

It's mainly intented to assert environment (bug in the test), rather than testing that observerFinalizationRegistry resolves to correct type (bug in the actual tested code).
Arguably I could split these into two, assertion to check globalThis for (not) being FinalizationRegistry and then an actual test for observerFinalizationRegistry. However I don't see much value in doing so.

import gc from "expose-gc/function"
import { observerFinalizationRegistry } from "../src/utils/observerFinalizationRegistry"

if (typeof globalThis.FinalizationRegistry !== "function") {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change this assertion also to expect to match the other checks?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... But then the error message won't be the same think think

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I did want to preserve the message.

@urugator
urugator merged commit 4ef8ff3 into main Jan 14, 2023
@github-actions github-actions Bot mentioned this pull request Jan 14, 2023
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.

4 participants