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

Convert engines, applications, and more to TS #2

Closed
wants to merge 1 commit into from

Conversation

wagenet
Copy link
Owner

@wagenet wagenet commented Feb 19, 2022

Requires emberjs#19964.

if (this.isDestroyed) {
throw new Error(`Cannot call \`.factoryFor\` after the owner has been destroyed`);
}
let normalizedName = this.registry.normalize(fullName);

assert('fullName must be a proper full name', this.registry.isValidFullName(normalizedName));

// TODO: This needs to return a Factory to be compatible with Owner.
// We should correctly the types so that this cast is not necessary.
return factoryFor(this, normalizedName, fullName) as Factory<unknown>;
Copy link
Owner Author

Choose a reason for hiding this comment

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

This was resolved!

@@ -11,36 +13,21 @@ export interface FactoryClass {
positionalParams?: string | string[] | undefined | null;
}

export interface Factory<T, C extends FactoryClass | object = FactoryClass> {
export interface Factory<T extends object, C extends FactoryClass | object = FactoryClass> {
Copy link
Owner Author

Choose a reason for hiding this comment

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

Currently, the code looks as if it only supports objects here. If emberjs#19532 we need to revisit this, but having it all in TS should actually make it easier!

@@ -81,13 +79,12 @@ const VALID_FULL_NAME_REGEXP = /^[^:]+:[^:]+$/;
*/
export default class Registry implements IRegistry {
readonly _failSet: Set<string>;
resolver: Resolver | null;
resolver: Resolver | (Resolve & NotResolver) | null;
Copy link
Owner Author

Choose a reason for hiding this comment

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

@@ -560,25 +553,28 @@ if (DEBUG) {
};
}

function resolve<T, C>(registry: Registry, _normalizedName: string): Factory<T, C> | undefined {
Copy link
Owner Author

Choose a reason for hiding this comment

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

Good riddance to unsafe generics.


if (mountPoint) {
state.engineBucket = { mountPoint };
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

I believe this was incorrect before. Looking at the code, it looks like engineBucket should never be set without mountPoint.

@@ -35,10 +44,10 @@ export const ActionManager: {
export declare class EventDispatcher extends EmberObject {
events: Record<string, string>;
finalEventNameMapping: Record<string, string>;
rootElement: string | HTMLElement;
rootElement: string | Element;
Copy link
Owner Author

Choose a reason for hiding this comment

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

Is this loosening correct?

setupHandlerForEmberEvent(event: string): void;

/** @private */
setup(addedEvents: Record<string, string | null>, rootElement: string | Element | null): void;
Copy link
Owner Author

Choose a reason for hiding this comment

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

I don't think we want to declare this twice!

@@ -52,7 +69,7 @@ const ApplicationInstance = EngineInstance.extend({
@private
@property {Object} customEvents
*/
customEvents: null,
customEvents: Record<string, string | null> | null = null;
Copy link
Owner Author

Choose a reason for hiding this comment

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

This needs to be a declare to allow overwriting.

@@ -61,10 +78,10 @@ const ApplicationInstance = EngineInstance.extend({
@private
@property {String|DOMElement} rootElement
*/
rootElement: null,
rootElement: string | Element | null = null;
Copy link
Owner Author

Choose a reason for hiding this comment

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

This needs to be a declare to allow overwriting.

},

// We overwrote this method from RegistryProxyMixin.
this.__registry__.unregister(fullName);
Copy link
Owner Author

Choose a reason for hiding this comment

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

This is a bit awkward but it's the best idea I have.

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.

1 participant