Skip to content

Commit

Permalink
fix(react): fix all 'react' driver flow / lint errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmilar committed Feb 17, 2021
1 parent 3d698b8 commit 7e05c6c
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/drivers/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,34 @@

import { extend, noop } from 'belter/src';

import type { ComponentDriverType } from '../component';
import type { ComponentDriverType, ZoidComponentInstance } from '../component';
import { CONTEXT } from '../constants';

// eslint-disable-next-line flowtype/require-exact-type
declare class ReactClassType {}

// eslint-disable-next-line flowtype/require-exact-type
declare class __ReactComponent {}
declare class _ReactComponentType {
state : {| parent? : ZoidComponentInstance<*> |},
props : mixed,
setState : (newStateOrFn : mixed) => void
}

// eslint-disable-next-line flowtype/require-exact-type
type Class<T> = { new(): T };

type ReactElementType = {|

|};

type ReactType = {|
Component : __ReactComponent,
Component : typeof _ReactComponentType,
createClass : ({| render : () => ReactElementType, componentDidMount : () => void, componentDidUpdate : () => void |}) => (typeof ReactClassType),
createElement : (string, ?{ [string] : mixed }, ...children : $ReadOnlyArray<ReactElementType>) => ReactElementType
|};

type ReactDomType = {|
findDOMNode : (typeof ReactClassType) => HTMLElement
findDOMNode : (_ReactComponentType) => HTMLElement
|};

type ReactLibraryType = {|
Expand All @@ -35,7 +42,7 @@ type ReactLibraryType = {|
/**
* Util to check if component is currently mounted
*/
function isMounted(component : typeof ReactClassType, ReactDOM : ReactDomType) : boolean {
function isMounted(component : _ReactComponentType, ReactDOM : ReactDomType) : boolean {
try {
return Boolean(ReactDOM.findDOMNode(component));
}
Expand All @@ -45,19 +52,16 @@ function isMounted(component : typeof ReactClassType, ReactDOM : ReactDomType) :
}
}

export const react : ComponentDriverType<*, ReactLibraryType, Class<_ReactComponentType>> = {

export const react : ComponentDriverType<*, ReactLibraryType, typeof ReactClassType> = {

register: (tag, propsDef, init, { React, ReactDOM }) => {
register: (tag, propsDef, init, { React, ReactDOM }) : Class<_ReactComponentType> => {

// $FlowFixMe
return class extends React.Component {
return class ZoidReactComponent extends React.Component {
render() : ReactElementType {
return React.createElement('div', null);
}

componentDidMount() {
// $FlowFixMe
const el = ReactDOM.findDOMNode(this);
const parent = init(extend({}, this.props));
parent.render(el, CONTEXT.IFRAME)
Expand Down

0 comments on commit 7e05c6c

Please sign in to comment.