Commit 9832f77
Changed files (5)
app/infrastructure/configuration.js
@@ -1,11 +1,11 @@
-import Config from 'react-native-config';
-
-var _configuration = {
+var _defaults = {
development: {
- API_HOST: 'http://localhost:3000'
+ API_HOST: 'http://localhost:3000',
+ ENV: 'development'
},
production: {
- API_HOST: 'https://www.stronglifters.com'
+ API_HOST: 'https://www.stronglifters.com',
+ ENV: 'production'
}
};
@@ -15,7 +15,6 @@ export default class Configuration {
}
value_for(key) {
- //return Config[key];
- return _configuration[this.environment][key];
+ return process.env[key] || _defaults[this.environment][key];
}
}
app/screens/login-screen.js
@@ -1,10 +1,11 @@
import React from 'react';
-import { View, Button, StyleSheet } from 'react-native';
+import { View, Button, Text } from 'react-native';
import { Container, Header, Title, Content, Spinner } from 'native-base';
import Account from '../domain/account'
import Api from '../infrastructure/api'
import DashboardScreen from './dashboard-screen'
import ApplicationComponent from '../components/application-component'
+import Configuration from '../infrastructure/configuration'
import * as events from '../services/events';
var t = require('tcomb-form-native');
@@ -13,6 +14,7 @@ var Form = t.form.Form;
export default class LoginScreen extends ApplicationComponent {
constructor(props) {
super(props)
+ this.configuration = new Configuration('development');
this.state = {
account: { username: 'mokha', password: 'password' },
eventsOfInterest: [events.LOGGED_IN],
@@ -28,7 +30,7 @@ export default class LoginScreen extends ApplicationComponent {
return (
<Container>
<Header>
- <Title>StrongLifters</Title>
+ <Title>StrongLifters ({this.configuration.value_for('ENV')})</Title>
</Header>
{this.content()}
</Container>
@@ -53,6 +55,7 @@ export default class LoginScreen extends ApplicationComponent {
options={this.formOptions()}
/>
<Button onPress={this.onLogin.bind(this)} title="Login" />
+ <Text>{this.configuration.value_for('API_HOST')}</Text>
</Content>
);
}
@@ -86,27 +89,3 @@ export default class LoginScreen extends ApplicationComponent {
});
}
}
-
-const styles = StyleSheet.create({
- container: {
- justifyContent: 'center',
- marginTop: 50,
- padding: 20,
- backgroundColor: '#ffffff',
- },
- buttonText: {
- fontSize: 18,
- color: 'white',
- alignSelf: 'center'
- },
- button: {
- height: 36,
- backgroundColor: '#48bbec',
- borderColor: '#48bbed',
- borderWidth: 1,
- borderRadius: 8,
- marginBottom: 10,
- alignSelf: 'stretch',
- justifyContent: 'center'
- }
-});
.babelrc
@@ -1,3 +1,4 @@
{
-"presets": ["react-native"]
-}
\ No newline at end of file
+"presets": ["react-native"],
+"plugins": ["transform-inline-environment-variables"]
+}
package.json
@@ -17,6 +17,7 @@
},
"devDependencies": {
"babel-jest": "18.0.0",
+ "babel-plugin-transform-inline-environment-variables": "^6.8.0",
"babel-preset-react-native": "1.9.1",
"jest": "18.0.0",
"react-test-renderer": "15.4.1"
yarn.lock
@@ -538,6 +538,12 @@ babel-plugin-transform-flow-strip-types@^6.18.0, babel-plugin-transform-flow-str
babel-plugin-syntax-flow "^6.18.0"
babel-runtime "^6.0.0"
+babel-plugin-transform-inline-environment-variables@^6.8.0:
+ version "6.8.0"
+ resolved "https://registry.yarnpkg.com/babel-plugin-transform-inline-environment-variables/-/babel-plugin-transform-inline-environment-variables-6.8.0.tgz#fc91dd08127dc6c2abdfd1721b11e9602a69ba10"
+ dependencies:
+ babel-runtime "^6.0.0"
+
babel-plugin-transform-object-assign@^6.5.0:
version "6.8.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-object-assign/-/babel-plugin-transform-object-assign-6.8.0.tgz#76e17f2dc0f36f14f548b9afd7aaef58d29ebb75"