Skip to content

Commit 3666149

Browse files
committed
prettified code using prettier
1 parent a90cb33 commit 3666149

File tree

12 files changed

+162
-155
lines changed

12 files changed

+162
-155
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"editor.formatOnSave": true
3+
}

src/Actions/actionCreator.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import {incrementCounter, decrementCounter} from './actionTypes'
1+
import { incrementCounter, decrementCounter } from "./actionTypes";
22

33
const incrementAction = () => ({
4-
type: incrementCounter
5-
})
4+
type: incrementCounter
5+
});
66

77
const decrementAction = () => ({
8-
type: decrementCounter
9-
})
8+
type: decrementCounter
9+
});
1010

11-
export {
12-
incrementAction,
13-
decrementAction
14-
}
11+
export { incrementAction, decrementAction };

src/Actions/actionTypes.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
const incrementCounter = "INCREMENT_COUNTER";
22
const decrementCounter = "DECREMENT_COUNTER";
33

4-
export {
5-
incrementCounter,
6-
decrementCounter
7-
}
4+
export { incrementCounter, decrementCounter };

src/Components/screen1.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import React, { Component } from "react";
2+
import { Text, View, TouchableOpacity } from "react-native";
3+
import { NavigationActions } from "react-navigation";
4+
import { connect } from "react-redux";
5+
6+
import { incrementAction, decrementAction } from "../Actions/actionCreator";
7+
8+
class Screen1View extends Component {
9+
static navigationOptions = {
10+
title: "Screen1"
11+
};
12+
13+
navigate = () => {
14+
const navigateToScreen2 = NavigationActions.navigate({
15+
routeName: "screen2",
16+
params: { name: "Shubhnik" }
17+
});
18+
this.props.navigation.dispatch(navigateToScreen2);
19+
};
20+
21+
render() {
22+
const { counterCount, incrementAction, decrementAction } = this.props;
23+
return (
24+
<View
25+
style={{
26+
flex: 1,
27+
backgroundColor: "yellowgreen",
28+
justifyContent: "center",
29+
alignItems: "center"
30+
}}
31+
>
32+
<Text>{counterCount}</Text>
33+
<View style={{ height: 100, flexDirection: "row" }}>
34+
<TouchableOpacity
35+
onPress={() => incrementAction()}
36+
style={{ flex: 1, justifyContent: "center", alignItems: "center" }}
37+
>
38+
<Text
39+
style={{ textDecorationLine: "underline", fontWeight: "600" }}
40+
>
41+
INCREMENT
42+
</Text>
43+
</TouchableOpacity>
44+
<TouchableOpacity
45+
onPress={() => decrementAction()}
46+
style={{ flex: 1, justifyContent: "center", alignItems: "center" }}
47+
>
48+
<Text
49+
style={{ textDecorationLine: "underline", fontWeight: "600" }}
50+
>
51+
DECREMENT
52+
</Text>
53+
</TouchableOpacity>
54+
</View>
55+
<TouchableOpacity
56+
style={{
57+
paddingVertical: 15,
58+
paddingHorizontal: 40,
59+
backgroundColor: "indigo"
60+
}}
61+
onPress={this.navigate}
62+
>
63+
<Text style={{ fontSize: 23, fontWeight: "600", color: "white" }}>
64+
Screen2
65+
</Text>
66+
</TouchableOpacity>
67+
</View>
68+
);
69+
}
70+
}
71+
72+
const mapStateToProps = state => ({
73+
counterCount: state.CounterReducer.counter
74+
});
75+
76+
const mapDispatchToProps = {
77+
incrementAction,
78+
decrementAction
79+
};
80+
81+
const Screen1 = connect(mapStateToProps, mapDispatchToProps)(Screen1View);
82+
83+
export default Screen1;

src/Components/screen1View.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/Components/screen2.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
import React, { Component } from 'react';
2-
import {
3-
Text,
4-
View,
5-
TouchableOpacity
6-
} from 'react-native';
1+
import React, { Component } from "react";
2+
import { Text, View, TouchableOpacity } from "react-native";
73

84
export default class Screen2 extends Component {
9-
static navigationOptions={
10-
title:'Screen2'
11-
}
12-
render() {
13-
return(
14-
<View style={{flex:1, backgroundColor:'powderblue'}}>
15-
<Text>{this.props.navigation.state.params.name}</Text>
16-
</View>
17-
)
18-
}
19-
}
5+
static navigationOptions = {
6+
title: "Screen2"
7+
};
8+
render() {
9+
return (
10+
<View style={{ flex: 1, backgroundColor: "powderblue" }}>
11+
<Text>{this.props.navigation.state.params.name}</Text>
12+
</View>
13+
);
14+
}
15+
}

src/Containers/screen1.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/Navigation/index.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
import React, { Component } from 'react';
2-
import { connect } from 'react-redux';
3-
import { addNavigationHelpers } from 'react-navigation';
4-
import NavigationStack from './navigationStack'
1+
import React, { Component } from "react";
2+
import { connect } from "react-redux";
3+
import { addNavigationHelpers } from "react-navigation";
4+
import NavigationStack from "./navigationStack";
55

66
class AppNavigation extends Component {
7-
render() {
8-
const { navigationState, dispatch } = this.props;
9-
return(
10-
<NavigationStack
11-
navigation={addNavigationHelpers({ dispatch, state: navigationState })}
12-
/>
13-
)
14-
}
15-
}
16-
17-
const mapStateToProps = (state) => {
18-
console.log(`****MPSP${JSON.stringify(state)}`)
19-
return ({
20-
navigationState: state.NavigationReducer
21-
})
7+
render() {
8+
const { navigationState, dispatch } = this.props;
9+
return (
10+
<NavigationStack
11+
navigation={addNavigationHelpers({ dispatch, state: navigationState })}
12+
/>
13+
);
14+
}
2215
}
2316

17+
const mapStateToProps = state => {
18+
return {
19+
navigationState: state.NavigationReducer
20+
};
21+
};
2422

25-
export default connect(mapStateToProps)(AppNavigation)
23+
export default connect(mapStateToProps)(AppNavigation);

src/Navigation/navigationStack.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { StackNavigator } from 'react-navigation';
2-
import Screen1 from '../Containers/screen1'
3-
import Screen2 from '../Components/screen2'
1+
import { StackNavigator } from "react-navigation";
2+
import Screen1 from "../Components/screen1";
3+
import Screen2 from "../Components/screen2";
44

55
const navigator = StackNavigator({
6-
screen1: {
7-
screen: Screen1
8-
},
9-
screen2: {
10-
screen: Screen2
11-
}
12-
})
6+
screen1: {
7+
screen: Screen1
8+
},
9+
screen2: {
10+
screen: Screen2
11+
}
12+
});
1313

14-
export default navigator;
14+
export default navigator;

src/Reducers/counterReducer.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import {incrementCounter, decrementCounter} from '../Actions/actionTypes'
1+
import { incrementCounter, decrementCounter } from "../Actions/actionTypes";
22

3-
const initialState = { counter: 0 }
3+
const initialState = { counter: 0 };
44

55
const counterReducer = (state = initialState, action) => {
6-
switch (action.type) {
7-
case incrementCounter:
8-
return {...state, counter:state.counter + 1}
6+
switch (action.type) {
7+
case incrementCounter:
8+
return { ...state, counter: state.counter + 1 };
99

10-
case decrementCounter:
11-
return {...state, counter:state.counter - 1}
10+
case decrementCounter:
11+
return { ...state, counter: state.counter - 1 };
1212

13-
default:
14-
return state
15-
}
16-
}
13+
default:
14+
return state;
15+
}
16+
};
1717

18-
export default counterReducer;
18+
export default counterReducer;

src/Reducers/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import {combineReducers} from 'redux';
2-
import CounterReducer from './counterReducer';
3-
import NavigationReducer from './navigationReducer'
1+
import { combineReducers } from "redux";
2+
import CounterReducer from "./counterReducer";
3+
import NavigationReducer from "./navigationReducer";
44

55
const AppReducer = combineReducers({
6-
CounterReducer,
7-
NavigationReducer
8-
})
6+
CounterReducer,
7+
NavigationReducer
8+
});
99

10-
export default AppReducer;
10+
export default AppReducer;

src/Reducers/navigationReducer.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import AppNavigator from '../Navigation/navigationStack'
2-
const initialState = AppNavigator.router.getStateForAction(AppNavigator.router.getActionForPathAndParams('screen1'))
3-
console.log(`*****NavState${JSON.stringify(initialState)}`);
1+
import AppNavigator from "../Navigation/navigationStack";
2+
const initialState = AppNavigator.router.getStateForAction(
3+
AppNavigator.router.getActionForPathAndParams("screen1")
4+
);
45
const navigationReducer = (state = initialState, action) => {
5-
const newState = AppNavigator.router.getStateForAction(action, state)
6-
return newState || state;
7-
}
6+
const newState = AppNavigator.router.getStateForAction(action, state);
7+
return newState || state;
8+
};
89

9-
export default navigationReducer;
10+
export default navigationReducer;

0 commit comments

Comments
 (0)