-
Notifications
You must be signed in to change notification settings - Fork 40
/
index.js
41 lines (36 loc) · 1.08 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
import React from 'react';
import ReactDOM from 'react-dom';
import { NavigationHandler } from 'navigation-react';
import getStateNavigator from './getStateNavigator';
import App from './App';
var stateNavigator = getStateNavigator();
registerControllers(stateNavigator);
stateNavigator.start();
ReactDOM.hydrate(
<NavigationHandler stateNavigator={stateNavigator}>
<App />
</NavigationHandler>,
document.getElementById('content')
);
function registerControllers(stateNavigator) {
stateNavigator.states.people.navigating =
stateNavigator.states.person.navigating = function(data, url, navigate) {
fetchData(url, navigate);
}
}
function fetchData(url, navigate) {
if (serverProps) {
navigate(serverProps);
serverProps = null;
return;
}
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState === 4){
navigate(JSON.parse(req.responseText));
}
};
req.open('get', url);
req.setRequestHeader('Content-Type', 'application/json');
req.send(null);
}