-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (55 loc) · 1.59 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
60
61
/* Generated by Krell, do not edit by hand */
import React from 'react';
import {
AppRegistry,
View,
Text
} from 'react-native';
import {name as appName} from './app.json';
import {krellUpdateRoot, onKrellReload} from './target/main.js';
let plainStyle = {
flex: 1,
alignItems: 'center',
justifyContent: 'center'
};
/*
* Establish a root that works for REPL based dev / prod. In the REPL case
* the real app root will be loaded async. In prod it won't really be async
* but we want to treat both cases the same.
*/
class KrellRoot extends React.Component {
constructor(props) {
super(props);
this.state = {loaded: false, root: null, tx: 0};
}
render() {
if (!this.state.loaded) {
return (
<View style={plainStyle}>
<Text>Waiting for Krell to load files.</Text>
</View>
);
} else {
return this.state.root(this.props);
}
}
componentDidMount() {
let krell = this;
// Mounting the app the first time
krellUpdateRoot((appRoot) => {
let newState = Object.assign({}, krell.state);
newState.root = appRoot;
newState.loaded = true;
krell.setState(newState);
});
// Hot reloading
onKrellReload(() => {
krell.setState((state, props) => {
let newState = Object.assign({}, state);
newState.tx++;
return newState;
});
});
}
}
AppRegistry.registerComponent(appName, () => KrellRoot);