forked from bartonhammond/snowflake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnowflake.js
91 lines (81 loc) · 2.54 KB
/
snowflake.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
86
87
88
89
90
91
'use strict';
/**
* # snowflake
* Snowflake ![snowflake](https://cloud.githubusercontent.com/assets/1282364/11599365/1a1c39d2-9a8c-11e5-8819-bc1e48b30525.png)
*/
/**
* ## imports
* * ```Provider``` will tie the React-Native to the Redux store
* * ```App``` contains Login and TabBar
* * ```configureStore``` will connect the ```reducers```, the
* ```thunk``` and the initial state.
*/
import React, { AppRegistry } from 'react-native';
import { Provider } from 'react-redux/native';
import App from './containers/App';
import configureStore from './lib/configureStore';
/**
* ## Actions
* The necessary actions for dispatching our bootstrap values
*/
import {setPlatform, setVersion} from './reducers/device/deviceActions';
import {setStore} from './reducers/global/globalActions';
/**
* ## States
* There are 4 initial states defined and together they make the Apps
* initial state
*/
import authInitialState from './reducers/auth/authInitialState';
import deviceInitialState from './reducers/device/deviceInitialState';
import globalInitialState from './reducers/global/globalInitialState';
import profileInitialState from './reducers/profile/profileInitialState';
/**
* The version of the app but not displayed yet
*/
var VERSION='0.0.8';
/**
*
* ## Initial state
* Create instances for the keys of each structure
* @returns {Object} object with 4 keys
*/
function getInitialState() {
const _initState = {
auth: new authInitialState,
device: (new deviceInitialState).set('isMobile',true).set('version',VERSION),
global: (new globalInitialState),
profile: new profileInitialState
};
return _initState;
}
/**
* ## Native
*
* ```configureStore``` with the ```initialState``` and set the
* ```platform``` and ```version``` into the store by ```dispatch```.
* *Note* the ```store``` itself is set into the ```store```. This
* will be used when doing hot loading
*/
export default function native(platform) {
let Snowflake = React.createClass( {
render() {
const store = configureStore(getInitialState());
store.dispatch(setPlatform(platform));
store.dispatch(setVersion(VERSION));
store.dispatch(setStore(store));
/**
* Provider wrap the ```App``` with a ```Provider``` and both
* have a ```store```
*/
return (
<Provider store={store}>
{() => <App store={store}/>}
</Provider>
);
}
});
/**
* registerComponent to the AppRegistery and off we go....
*/
AppRegistry.registerComponent('snowflake', () => Snowflake);
}