Skip to content

Commit

Permalink
Revert "feat: support additional…" (#467)
Browse files Browse the repository at this point in the history
This reverts commit d2f3f09.
  • Loading branch information
ravishekhar authored Dec 18, 2024
1 parent d2f3f09 commit b2c8a19
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 238 deletions.
4 changes: 2 additions & 2 deletions src/child/child.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ export type ChildComponent<P, X> = {|
init: () => ZalgoPromise<void>,
|};

export function childComponent<P, X, C, ExtType>(
options: NormalizedComponentOptionsType<P, X, C, ExtType>
export function childComponent<P, X, C>(
options: NormalizedComponentOptionsType<P, X, C>
): ChildComponent<P, X> {
const { tag, propsDef, autoResize, allowedParentDomains } = options;

Expand Down
75 changes: 24 additions & 51 deletions src/component/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {

import { childComponent, type ChildComponent } from "../child";
import {
type ParentComponent,
type RenderOptionsType,
type ParentHelpers,
parentComponent,
Expand Down Expand Up @@ -107,10 +106,9 @@ export type ExportsDefinition<X> =
| ExportsConfigDefinition
| ExportsMapperDefinition<X>;

export type ComponentOptionsType<P, X, C, ExtType> = {|
export type ComponentOptionsType<P, X, C> = {|
tag: string,

getExtensions?: (parent: ParentComponent<P, X>) => ExtType,
url: string | (({| props: PropsType<P> |}) => string),
domain?: DomainMatcher,
bridgeUrl?: string,
Expand Down Expand Up @@ -157,11 +155,10 @@ type AutoResizeType = {|
element?: string,
|};

export type NormalizedComponentOptionsType<P, X, C, ExtType> = {|
export type NormalizedComponentOptionsType<P, X, C> = {|
tag: string,
name: string,

getExtensions: (parent: ParentComponent<P, X>) => ExtType,
url: string | (({| props: PropsType<P> |}) => string),
domain: ?DomainMatcher,
bridgeUrl: ?string,
Expand Down Expand Up @@ -195,13 +192,12 @@ export type NormalizedComponentOptionsType<P, X, C, ExtType> = {|
exports: ExportsMapperDefinition<X>,
|};

export type ZoidComponentInstance<P, X = void, C = void, ExtType = void> = {|
...ExtType,
export type ZoidComponentInstance<P, X = void, C = void> = {|
...ParentHelpers<P>,
...X,
...C,
isEligible: () => boolean,
clone: () => ZoidComponentInstance<P, X, C, ExtType>,
clone: () => ZoidComponentInstance<P, X, C>,
render: (
container?: ContainerReferenceType,
context?: $Values<typeof CONTEXT>
Expand All @@ -214,14 +210,14 @@ export type ZoidComponentInstance<P, X = void, C = void, ExtType = void> = {|
|};

// eslint-disable-next-line flowtype/require-exact-type
export type ZoidComponent<P, X = void, C = void, ExtType = void> = {
(props?: PropsInputType<P> | void): ZoidComponentInstance<P, X, C, ExtType>,
export type ZoidComponent<P, X = void, C = void> = {
(props?: PropsInputType<P> | void): ZoidComponentInstance<P, X, C>,
// eslint-disable-next-line no-undef
driver: <T>(string, mixed) => T,
isChild: () => boolean,
xprops?: PropsType<P>,
canRenderTo: (CrossDomainWindowType) => ZalgoPromise<boolean>,
instances: $ReadOnlyArray<ZoidComponentInstance<P, X, C, ExtType>>,
instances: $ReadOnlyArray<ZoidComponentInstance<P, X, C>>,
};

const getDefaultAttributes = (): AttributesType => {
Expand All @@ -244,26 +240,15 @@ const getDefaultDimensions = (): CssDimensionsType => {
return {};
};

function getDefaultGetExtensions<P, X, ExtType>(): (
parent: ParentComponent<P, 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> {
function normalizeOptions<P, X, C>(
options: ComponentOptionsType<P, X, C>
): NormalizedComponentOptionsType<P, X, C> {
const {
tag,
url,
domain,
bridgeUrl,
props = {},
getExtensions = getDefaultGetExtensions<P, X, ExtType>(),
dimensions = getDefaultDimensions(),
autoResize = getDefaultAutoResize(),
allowedParentDomains = WILDCARD,
Expand Down Expand Up @@ -344,42 +329,31 @@ function normalizeOptions<P, X, C, ExtType>(
eligible,
children,
exports: xports,
getExtensions,
};
}

let cleanInstances = cleanup();
const cleanZoid = cleanup();

export type Component<P, X, C, ExtType> = {|
init: (
props?: PropsInputType<P> | void
) => ZoidComponentInstance<P, X, C, ExtType>,
instances: $ReadOnlyArray<ZoidComponentInstance<P, X, C, ExtType>>,
export type Component<P, X, C> = {|
init: (props?: PropsInputType<P> | void) => ZoidComponentInstance<P, X, C>,
instances: $ReadOnlyArray<ZoidComponentInstance<P, X, C>>,
driver: (string, mixed) => mixed,
isChild: () => boolean,
canRenderTo: (CrossDomainWindowType) => ZalgoPromise<boolean>,
registerChild: () => ?ChildComponent<P, X>,
|};

export function component<P, X, C, ExtType>(
opts: ComponentOptionsType<P, X, C, ExtType>
): Component<P, X, C, ExtType> {
export function component<P, X, C>(
opts: ComponentOptionsType<P, X, C>
): Component<P, X, C> {
if (__DEBUG__) {
validateOptions(opts);
}

const options = normalizeOptions(opts);

const {
name,
tag,
defaultContext,
propsDef,
eligible,
children,
getExtensions,
} = options;
const { name, tag, defaultContext, propsDef, eligible, children } = options;

const global = getGlobal(window);
const driverCache = {};
Expand Down Expand Up @@ -497,7 +471,7 @@ export function component<P, X, C, ExtType>(

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

Expand Down Expand Up @@ -616,7 +590,6 @@ export function component<P, X, C, ExtType>(
};

instance = {
...getExtensions(parent),
...parent.getExports(),
...parent.getHelpers(),
...getChildren(),
Expand Down Expand Up @@ -690,15 +663,15 @@ export type ComponentDriverType<P, L, D, X, C> = {|
export type ZoidProps<P> = PropsType<P>;

// eslint-disable-next-line no-undef
export type CreateZoidComponent = <P, X, C, ExtType>(
export type CreateZoidComponent = <P, X, C>(
// eslint-disable-next-line no-undef
options: ComponentOptionsType<P, X, C, ExtType>
options: ComponentOptionsType<P, X, C>
// eslint-disable-next-line no-undef
) => ZoidComponent<P, X, C, ExtType>;
) => ZoidComponent<P, X, C>;

export const create: CreateZoidComponent = <P, X, C, ExtType>(
options: ComponentOptionsType<P, X, C, ExtType>
): ZoidComponent<P, X, C, ExtType> => {
export const create: CreateZoidComponent = <P, X, C>(
options: ComponentOptionsType<P, X, C>
): ZoidComponent<P, X, C> => {
setupPostRobot();

const comp = component(options);
Expand Down
8 changes: 4 additions & 4 deletions src/component/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { CONTEXT, PROP_TYPE } from "../constants";

import type { ComponentOptionsType } from "./index";

function validatepropsDefinitions<P, X, C, ExtType>(
options: ComponentOptionsType<P, X, C, ExtType>
function validatepropsDefinitions<P, X, C>(
options: ComponentOptionsType<P, X, C>
) {
if (options.props && !(typeof options.props === "object")) {
throw new Error(`Expected options.props to be an object`);
Expand Down Expand Up @@ -49,8 +49,8 @@ function validatepropsDefinitions<P, X, C, ExtType>(
}

// eslint-disable-next-line complexity
export function validateOptions<P, X, C, ExtType>(
options: ?ComponentOptionsType<P, X, C, ExtType>
export function validateOptions<P, X, C>(
options: ?ComponentOptionsType<P, X, C>
) {
// eslint-ignore-line

Expand Down
10 changes: 5 additions & 5 deletions src/parent/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ type RenderOptions = {|
rerender: Rerender,
|};

export type ParentComponent<P, X> = {|
type ParentComponent<P, X> = {|
init: () => void,
render: (RenderOptions) => ZalgoPromise<void>,
getProps: () => PropsType<P>,
Expand All @@ -271,19 +271,19 @@ const getDefaultOverrides = <P>(): ParentDelegateOverrides<P> => {
return {};
};

type ParentOptions<P, X, C, ExtType> = {|
type ParentOptions<P, X, C> = {|
uid: string,
options: NormalizedComponentOptionsType<P, X, C, ExtType>,
options: NormalizedComponentOptionsType<P, X, C>,
overrides?: ParentDelegateOverrides<P>,
parentWin?: CrossDomainWindowType,
|};

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

0 comments on commit b2c8a19

Please sign in to comment.