-
Notifications
You must be signed in to change notification settings - Fork 247
/
react.js
57 lines (43 loc) · 1.76 KB
/
react.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* @flow */
/* eslint react/no-deprecated: off, react/no-find-dom-node: off, react/display-name: off, react/no-did-mount-set-state: off, react/destructuring-assignment: off, react/prop-types: off */
import { extend, noop } from 'belter/src';
import type { ComponentDriverType } from '../component';
import { CONTEXT } from '../constants';
declare class ReactClassType {}
declare class __ReactComponent {}
type ReactElementType = {|
|};
type ReactType = {|
Component : __ReactComponent,
createClass : ({| render : () => ReactElementType, componentDidMount : () => void, componentDidUpdate : () => void |}) => (typeof ReactClassType),
createElement : (string, ?{ [string] : mixed }, ...children : $ReadOnlyArray<ReactElementType>) => ReactElementType
|};
type ReactDomType = {|
findDOMNode : (typeof ReactClassType) => HTMLElement
|};
type ReactLibraryType = {|
React : ReactType,
ReactDOM : ReactDomType
|};
export const react : ComponentDriverType<*, ReactLibraryType, typeof ReactClassType, *, *> = {
register: (tag, propsDef, init, { React, ReactDOM }) => {
// $FlowFixMe
return class 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);
this.setState({ parent });
}
componentDidUpdate() {
if (this.state && this.state.parent) {
this.state.parent.updateProps(extend({}, this.props)).catch(noop);
}
}
};
}
};