-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
60 lines (51 loc) · 1.36 KB
/
index.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
58
59
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider, } from 'react-redux';
import './index.css';
import App from './App';
import { createReduxStore, } from './store';
import INITIAL_STATE from './reducers/initial-state';
import registerServiceWorker from './registerServiceWorker';
export class TheUIGuy {
constructor() {
this.isRendered = false;
this.reactInstance = null;
this.isInitialized = false;
const initialState = { ...INITIAL_STATE, };
this.store = createReduxStore(initialState);
this.render();
}
/**
* Renders the component in the root element given via configuration
* (config.root) if the component is not yet rendered.
*
* @return {TheUIGuy} instance of this component.
* @public
*/
render() {
if (!this.isRendered) {
this.reactInstance = ReactDOM.render(
<Provider store={this.store}>
<App/>
</Provider>,
document.getElementById('root'));
registerServiceWorker();
this.isRendered = true;
}
return this;
}
/**
* Destroys this component.
*
* @public
*/
destroy() {
if (this.isRendered) {
ReactDOM.unmountComponentAtNode(document.getElementById('root'));
this.reactInstance = null;
this.isRendered = false;
this.isInitialized = false;
}
}
}
window.component = new TheUIGuy();