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

Refactored type and property helpers #6721

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kraenhansen
Copy link
Member

@kraenhansen kraenhansen commented Jun 12, 2024

What, How & Why?

This refactors the type and property helpers into multiple files.

I want to move away from the "internal-pattern" to get rid of the circular reference warnings, which I somewhat started here and I'll have to do a separate (massive) PR later to complete that.

At some point, I think it'll also be nice to move some of the functions introduced in #6613 into type specific property helpers.

@kraenhansen kraenhansen added T-Internal no-changelog no-jira-ticket Skip checking the PR title for Jira reference labels Jun 12, 2024
@kraenhansen kraenhansen requested a review from elle-j June 12, 2024 14:54
@kraenhansen kraenhansen self-assigned this Jun 12, 2024
@cla-bot cla-bot bot added the cla: yes label Jun 12, 2024
@kraenhansen kraenhansen marked this pull request as draft June 12, 2024 14:57
@kraenhansen
Copy link
Member Author

Putting this into draft as it seems I'm missing a few @internal annotations.

Copy link
Member

@elle-j elle-j left a comment

Choose a reason for hiding this comment

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

Looks good to go for me 👍 Nice refactoring Kraen 🙂

PropertyHelpers,
PropertyOptions,
} from "./property-accessors/types";
import { createIntPropertyAccessor } from "./property-accessors/Int";
Copy link
Member

Choose a reason for hiding this comment

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

We could move this up with the other create imports 👍

import { createDictionaryPropertyAccessor } from "./property-accessors/Dictionary";
import { createDefaultPropertyAccessor } from "./property-accessors/default";
import { createSetPropertyAccessor } from "./property-accessors/Set";
import { createMixedPropertyAccessor } from "./property-accessors/Mixed";
import {
Copy link
Member

Choose a reason for hiding this comment

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

Following the pattern in TypeHelpers.ts when there are many related imports in between.

Suggested change
import {
import {

Comment on lines +38 to 47
function createUnsupportedTypeHelpers(): TypeHelpers {
return {
fromBinding() {
throw new Error("Not yet supported");
},
toBinding() {
throw new Error("Not yet supported");
},
};
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Would it make sense to have a type-helpers/unsupported.ts? 🤔

packages/realm/src/property-accessors/Int.ts Outdated Show resolved Hide resolved
};
}

import type { PropertyAccessor, PropertyHelpers, PropertyOptions } from "./types";
Copy link
Member

Choose a reason for hiding this comment

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

I think this accidentally got placed here instead of at the top.

packages/realm/src/property-accessors/default.ts Outdated Show resolved Hide resolved
import { createUuidTypeHelpers } from "./type-helpers/Uuid";
import { createArrayTypeHelpers } from "./type-helpers/Array";

import type { TypeHelpers, TypeOptions } from "./type-helpers/types";
Copy link
Member

Choose a reason for hiding this comment

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

type may be redundant for these imports. (If updating, there are more occurrences.)

Copy link
Member Author

@kraenhansen kraenhansen Jun 24, 2024

Choose a reason for hiding this comment

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

In general, I want to leverage the import type more to avoid circular dependencies at runtime (as these imports are stripped from JS files when running tsc). I still have an outstanding task of fixing these circular imports which got leaked into the developers bundling process, after we migrated away from Rollup.

That being said, the TypeScript compiler seems pretty good at shaking off these type-only imports, even if the type keyword isn't used.

Copy link
Member

Choose a reason for hiding this comment

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

As you mention, I thought TS handled that implicitly when the import itself was a type as in this case. But are you saying that you prefer to still be explicit to be certain?

packages/realm/src/type-helpers/ObjectId.ts Outdated Show resolved Hide resolved
@kraenhansen kraenhansen force-pushed the kh/refactored-type-and-property-helpers branch from 70fd921 to 80e5d87 Compare June 24, 2024 20:45
@kraenhansen kraenhansen marked this pull request as ready for review June 28, 2024 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes no-changelog no-jira-ticket Skip checking the PR title for Jira reference T-Internal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants