Skip to content

Commit

Permalink
Fix more type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ravishekhar committed Dec 6, 2024
1 parent 5deaab4 commit c7f6c71
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
30 changes: 20 additions & 10 deletions src/component/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export type ExportsDefinition<X> =
export type ComponentOptionsType<P, X, C, ExtType> = {|
tag: string,

getExtensions?: (parentProps: ParentPropType<P, X>) => ExtType,
getExtensions?: (parentProps: X) => ExtType,
url: string | (({| props: PropsType<P> |}) => string),
domain?: DomainMatcher,
bridgeUrl?: string,
Expand Down Expand Up @@ -160,7 +160,7 @@ export type NormalizedComponentOptionsType<P, X, C, ExtType> = {|
tag: string,
name: string,

getExtensions?: (parentProps: ParentPropType<P, X>) => ExtType,
getExtensions: (parentProps: X) => ExtType,
url: string | (({| props: PropsType<P> |}) => string),
domain: ?DomainMatcher,
bridgeUrl: ?string,
Expand Down Expand Up @@ -200,7 +200,7 @@ export type ZoidComponentInstance<P, X = void, C = void, ExtType = void> = {|
...C,
...ExtType,
isEligible: () => boolean,
clone: () => ZoidComponentInstance<P, X, C>,
clone: () => ZoidComponentInstance<P, X, C, ExtType>,
render: (
container?: ContainerReferenceType,
context?: $Values<typeof CONTEXT>
Expand Down Expand Up @@ -243,6 +243,14 @@ const getDefaultDimensions = (): CssDimensionsType => {
return {};
};

function getDefaultGetExtensions<X, ExtType>(): (parentProps: X) => ExtType {
return function getExtensions(): ExtType {
// $FlowFixMe
const ext: ExtType = {};
return ext;
};
}

function normalizeOptions<P, X, C, ExtType>(
options: ComponentOptionsType<P, X, C, ExtType>
): NormalizedComponentOptionsType<P, X, C, ExtType> {
Expand All @@ -252,7 +260,7 @@ function normalizeOptions<P, X, C, ExtType>(
domain,
bridgeUrl,
props = {},
getExtensions,
getExtensions = getDefaultGetExtensions<X, ExtType>(),
dimensions = getDefaultDimensions(),
autoResize = getDefaultAutoResize(),
allowedParentDomains = WILDCARD,
Expand Down Expand Up @@ -340,9 +348,11 @@ function normalizeOptions<P, X, C, ExtType>(
let cleanInstances = cleanup();
const cleanZoid = cleanup();

export type Component<P, X, C> = {|
init: (props?: PropsInputType<P> | void) => ZoidComponentInstance<P, X, C>,
instances: $ReadOnlyArray<ZoidComponentInstance<P, X, C>>,
export type Component<P, X, C, ExtType> = {|
init: (
props?: PropsInputType<P> | void
) => ZoidComponentInstance<P, X, C, ExtType>,
instances: $ReadOnlyArray<ZoidComponentInstance<P, X, C, ExtType>>,
driver: (string, mixed) => mixed,
isChild: () => boolean,
canRenderTo: (CrossDomainWindowType) => ZalgoPromise<boolean>,
Expand All @@ -351,7 +361,7 @@ export type Component<P, X, C> = {|

export function component<P, X, C, ExtType>(
opts: ComponentOptionsType<P, X, C, ExtType>
): Component<P, X, C> {
): Component<P, X, C, ExtType> {
if (__DEBUG__) {
validateOptions(opts);
}
Expand Down Expand Up @@ -484,7 +494,7 @@ export function component<P, X, C, ExtType>(

const init = (
inputProps?: PropsInputType<P> | void
): ZoidComponentInstance<P, X, C> => {
): ZoidComponentInstance<P, X, C, ExtType> => {
// eslint-disable-next-line prefer-const
let instance;

Expand Down Expand Up @@ -606,7 +616,7 @@ export function component<P, X, C, ExtType>(
...parent.getExports(),
...parent.getHelpers(),
...getChildren(),
...(getExtensions ? getExtensions(parent.getExports()) : {}),
...getExtensions(parent.getExports()),
isEligible,
clone,
render: (container, context) => render(window, container, context),
Expand Down
4 changes: 2 additions & 2 deletions src/parent/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ type ParentOptions<P, X, C, ExtType> = {|
parentWin?: CrossDomainWindowType,
|};

export function parentComponent<P, X, C>({
export function parentComponent<P, X, C, ExtType>({
uid,
options,
overrides = getDefaultOverrides(),
parentWin = window,
}: ParentOptions<P, X, C>): ParentComponent<P, X> {
}: ParentOptions<P, X, C, ExtType>): ParentComponent<P, X> {
const {
propsDef,
containerTemplate,
Expand Down

0 comments on commit c7f6c71

Please sign in to comment.