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

Migrate lifecycles folder to typescript #1210

Merged
merged 7 commits into from Apr 8, 2024
Merged

Migrate lifecycles folder to typescript #1210

merged 7 commits into from Apr 8, 2024

Conversation

joeldenning
Copy link
Member

No description provided.

.eslintrc Outdated
"parser": "@babel/eslint-parser",
"parser": "@typescript-eslint/parser",
"parserOptions": {
"lib": ["dom", "es5", "es2020"]
Copy link
Member Author

Choose a reason for hiding this comment

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

I was surprised that I had to specify this option because I thought it would inherit it from the tsconfig.json. Apparently it did not.

Copy link

Choose a reason for hiding this comment

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

Apparently, you can also set the project setting to point to the tsconfig.json. I would've expected it to automatically detect tsconfig.json at the same level as the .eslintrc too.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

export function flattenFnArray(
appOrParcel: LifeCycles<unknown>,
lifecycle: "bootstrap" | "mount" | "update" | "unmount" | "unload",
isParcel: boolean
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a runtime change that maybe fixes a bug? The objectType function looks for a runtime unmountThisParcel property, but flattenFnArray is being called with the user-defined result of the load promise, rather than with InternalApplication | InternalParcel.

Requiring the caller of flattenFnArray to specify whether it's a parcel or not eliminates that possible bug

@@ -26,14 +33,14 @@ export function getProps(appOrParcel) {
customProps
);
}
const result = assign({}, customProps, {
const result: SingleSpaProps = Object.assign({}, customProps, {
Copy link
Member Author

Choose a reason for hiding this comment

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

Switched to native Object.assign(), since we no longer support IE in single-spa@7

Copy link

@ibacher ibacher left a comment

Choose a reason for hiding this comment

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

LGTM!

.eslintrc Outdated
"parser": "@babel/eslint-parser",
"parser": "@typescript-eslint/parser",
"parserOptions": {
"lib": ["dom", "es5", "es2020"]
Copy link

Choose a reason for hiding this comment

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

Apparently, you can also set the project setting to point to the tsconfig.json. I would've expected it to automatically detect tsconfig.json at the same level as the .eslintrc too.

if (appOrParcel.loadPromise) {
return appOrParcel.loadPromise;
if ((app as LoadedApp).loadPromise) {
return (app as LoadedApp).loadPromise;
Copy link

Choose a reason for hiding this comment

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

The fact that TS can't infer this is... annoying.

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed

unmountSelf(): Promise<AppOrParcel>;
}

export function getProps(appOrParcel: AppOrParcel): SingleSpaProps {
Copy link

Choose a reason for hiding this comment

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

It might be useful if the return type here was SingleSpaProps & CustomProps, although I suppose the real utility would be if that was the type passed to the lifecycle functions itself (since CustomProps should be down-castable to the custom props an app expects.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 updated

@@ -26,14 +33,14 @@ export function getProps(appOrParcel) {
customProps
);
}
const result = assign({}, customProps, {
const result: SingleSpaProps = Object.assign({}, customProps, {
name,
mountParcel: mountParcel.bind(appOrParcel),
singleSpa,
});

if (isParcel(appOrParcel)) {
Copy link

Choose a reason for hiding this comment

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

It might be useful to redefine isParcel() as:

function isParcel(appOrParcel: AppOrParcel): appOrParcel is InternalParcel

This shouldn't requires any runtime changes, but it eliminates the need for a cast here. Just a thought for a future PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't aware of the is appOrParcel is InternalParcel syntax - very cool. I've updated it.

@joeldenning joeldenning merged commit d717968 into 7.0 Apr 8, 2024
2 checks passed
@joeldenning joeldenning deleted the ts-7 branch April 8, 2024 19:38
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