This repository has been archived by the owner on Sep 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
App.js
85 lines (69 loc) · 2.11 KB
/
App.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// @flow
// @author Dmitry Patsura <talk@dmtry.me> https://github.com/ovrå
import React, { PureComponent } from 'react';
import { AppRegistry } from 'react-native';
import { Provider } from 'react-redux';
import { before } from 'github-flow-js/Client';
import { initApp } from 'actions';
import { default as Navigator } from './Navigator';
import { configureStore, getInitialState } from 'utils';
import { captureException } from 'utils/errors';
type ApplicationStateNotInitialized = {
initialized: false,
store: null
}
type ApplicationStateInitialized = {
initialized: true,
store: Store
}
type ApplicationState = ApplicationStateNotInitialized | ApplicationStateInitialized;
class App extends PureComponent<ApplicationState> {
state: ApplicationState = {
initialized: false,
store: null
};
componentWillMount() {
getInitialState().then(
(initialState: Object) => {
this.setState({
initialized: true,
store: configureStore(initialState)
});
},
(error) => {
captureException(error);
this.setState({
initialized: true,
store: configureStore({})
});
}
);
}
render() {
if (!this.state.initialized) {
return null;
}
const store = this.state.store;
before(
(requestOptions) => {
const state = store.getState();
if (state.app.authorization) {
requestOptions.headers = {
...requestOptions.headers,
Authorization: 'token ' + state.app.authorization.token
};
}
}
);
const state = store.getState();
if (state.app.user) {
store.dispatch(initApp());
}
return (
<Provider store={store}>
<Navigator />
</Provider>
);
}
}
AppRegistry.registerComponent('ghubber', () => App);