@@ -14,94 +14,96 @@ type Props = {
1414
1515const noop = ( ) => { } ;
1616
17- const Element = ( type : string , hocOptions : { sourceType ?: string } = { } ) => class extends React . Component {
18- static propTypes = {
19- elementRef : PropTypes . func ,
20- onChange : PropTypes . func ,
21- onBlur : PropTypes . func ,
22- onFocus : PropTypes . func ,
23- onReady : PropTypes . func ,
24- }
25- static defaultProps = {
26- elementRef : noop ,
27- onChange : noop ,
28- onBlur : noop ,
29- onFocus : noop ,
30- onReady : noop ,
31- }
17+ const Element = ( type : string , hocOptions : { sourceType ?: string } = { } ) =>
18+ class extends React . Component {
19+ static propTypes = {
20+ elementRef : PropTypes . func ,
21+ onChange : PropTypes . func ,
22+ onBlur : PropTypes . func ,
23+ onFocus : PropTypes . func ,
24+ onReady : PropTypes . func ,
25+ } ;
26+ static defaultProps = {
27+ elementRef : noop ,
28+ onChange : noop ,
29+ onBlur : noop ,
30+ onFocus : noop ,
31+ onReady : noop ,
32+ } ;
3233
33- static contextTypes = {
34- elements : PropTypes . object . isRequired ,
35- registerElement : PropTypes . func . isRequired ,
36- unregisterElement : PropTypes . func . isRequired ,
37- }
34+ static contextTypes = {
35+ elements : PropTypes . object . isRequired ,
36+ registerElement : PropTypes . func . isRequired ,
37+ unregisterElement : PropTypes . func . isRequired ,
38+ } ;
3839
39- constructor ( props : Props , context : ElementContext ) {
40- super ( props , context ) ;
40+ constructor ( props : Props , context : ElementContext ) {
41+ super ( props , context ) ;
4142
42- const options = this . _extractOptions ( this . props ) ;
43- this . _element = this . context . elements . create ( type , options ) ;
44- this . _setupEventListeners ( ) ;
45- this . _options = options ;
46- }
43+ const options = this . _extractOptions ( this . props ) ;
44+ this . _element = this . context . elements . create ( type , options ) ;
45+ this . _setupEventListeners ( ) ;
46+ this . _options = options ;
47+ }
4748
48- componentDidMount ( ) {
49- this . _element . mount ( this . _ref ) ;
50- if ( hocOptions . sourceType ) {
51- this . context . registerElement ( hocOptions . sourceType , this . _element ) ;
49+ componentDidMount ( ) {
50+ this . _element . mount ( this . _ref ) ;
51+ if ( hocOptions . sourceType ) {
52+ this . context . registerElement ( hocOptions . sourceType , this . _element ) ;
53+ }
5254 }
53- }
54- componentWillReceiveProps ( nextProps : Props ) {
55- const options = this . _extractOptions ( nextProps ) ;
56- if ( Object . keys ( options ) . length !== 0 && ! shallowEqual ( options , this . _options ) ) {
57- this . _options = options ;
58- this . _element . update ( options ) ;
55+ componentWillReceiveProps ( nextProps : Props ) {
56+ const options = this . _extractOptions ( nextProps ) ;
57+ if (
58+ Object . keys ( options ) . length !== 0 &&
59+ ! shallowEqual ( options , this . _options )
60+ ) {
61+ this . _options = options ;
62+ this . _element . update ( options ) ;
63+ }
64+ }
65+ componentWillUnmount ( ) {
66+ this . _element . destroy ( ) ;
67+ this . context . unregisterElement ( this . _element ) ;
5968 }
60- }
61- componentWillUnmount ( ) {
62- this . _element . destroy ( ) ;
63- this . context . unregisterElement ( this . _element ) ;
64- }
65- props : Props
66- context : ElementContext
67- _element : ElementShape
68- _ref : ?HTMLElement
69- _options : Object
69+ props : Props ;
70+ context : ElementContext ;
71+ _element : ElementShape ;
72+ _ref : ?HTMLElement ;
73+ _options : Object ;
7074
71- _setupEventListeners ( ) {
72- this . _element . on ( 'ready' , ( ) => {
73- this . props . elementRef ( this . _element ) ;
74- this . props . onReady ( ) ;
75- } ) ;
75+ _setupEventListeners ( ) {
76+ this . _element . on ( 'ready' , ( ) => {
77+ this . props . elementRef ( this . _element ) ;
78+ this . props . onReady ( ) ;
79+ } ) ;
7680
77- this . _element . on ( 'change' , ( change ) => {
78- this . props . onChange ( change ) ;
79- } ) ;
81+ this . _element . on ( 'change' , change => {
82+ this . props . onChange ( change ) ;
83+ } ) ;
8084
81- this . _element . on ( 'blur' , ( ...args ) => this . props . onBlur ( ...args ) ) ;
82- this . _element . on ( 'focus' , ( ...args ) => this . props . onFocus ( ...args ) ) ;
83- }
85+ this . _element . on ( 'blur' , ( ...args ) => this . props . onBlur ( ...args ) ) ;
86+ this . _element . on ( 'focus' , ( ...args ) => this . props . onFocus ( ...args ) ) ;
87+ }
8488
85- _extractOptions ( props : Props ) : Object {
86- const {
87- elementRef,
88- onChange,
89- onFocus,
90- onBlur,
91- onReady,
92- ...options
93- } = props ;
94- return options ;
95- }
89+ _extractOptions ( props : Props ) : Object {
90+ const {
91+ elementRef,
92+ onChange,
93+ onFocus,
94+ onBlur,
95+ onReady,
96+ ...options
97+ } = props ;
98+ return options ;
99+ }
96100
97- handleRef = ( ref : HTMLElement ) => {
98- this . _ref = ref ;
99- }
100- render ( ) {
101- return (
102- < span ref = { this . handleRef } />
103- ) ;
104- }
105- } ;
101+ handleRef = ( ref : HTMLElement ) => {
102+ this . _ref = ref ;
103+ } ;
104+ render ( ) {
105+ return < span ref = { this . handleRef } /> ;
106+ }
107+ } ;
106108
107109export default Element ;
0 commit comments