Skip to content

Commit

Permalink
cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
alinz committed Jun 22, 2017
1 parent a0d2527 commit a8560ad
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 33 deletions.
8 changes: 4 additions & 4 deletions Counters/index.android.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
'use strict'

import { AppRegistry } from 'react-native';
import Main from './src';
import { AppRegistry } from 'react-native'
import Main from './src'

AppRegistry.registerComponent('Counters', () => Main);
AppRegistry.registerComponent('Counters', () => Main)
8 changes: 4 additions & 4 deletions Counters/index.ios.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
'use strict'

import { AppRegistry } from 'react-native';
import Main from './src';
import { AppRegistry } from 'react-native'
import Main from './src'

AppRegistry.registerComponent('Counters', () => Main);
AppRegistry.registerComponent('Counters', () => Main)
10 changes: 6 additions & 4 deletions Counters/src/createStore.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { createStore, applyMiddleware, combineReducers } from 'redux';
import thunk from 'redux-thunk';
// @flow

import { createStore, applyMiddleware, combineReducers } from 'redux'
import thunk from 'redux-thunk'

import { app } from './modules'

const middleware = applyMiddleware(thunk);
const middleware = applyMiddleware(thunk)

export default (data = {}) => {
export default (data: Object = {}) => {
const rootReducer = combineReducers({
//every modules reducer should be define here
[app.NAME]: app.reducer
Expand Down
6 changes: 3 additions & 3 deletions Counters/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @flow

import React from 'react'
import { Component } from 'react-native';
import { Provider } from 'react-redux';
import { Provider } from 'react-redux'

import { app } from './modules'

import createStore from './createStore'

const store = createStore()
Expand Down
22 changes: 8 additions & 14 deletions Counters/src/modules/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const styles = StyleSheet.create({
})

const renderCounters = (counters, decrement, increment, incrementWithDelay) => {
return Object.keys(counters).map((id) => {
return Object.keys(counters).map(id => {
const value = counters[id]
return (
<Counter
Expand All @@ -28,14 +28,8 @@ const renderCounters = (counters, decrement, increment, incrementWithDelay) => {
})
}

const App = (props) => {
const {
addNewCounter,
counters,
decrement,
increment,
incrementWithDelay
} = props
const App = props => {
const { addNewCounter, counters, decrement, increment, incrementWithDelay } = props

return (
<View style={styles.container}>
Expand Down Expand Up @@ -65,13 +59,13 @@ App.propTypes = {
//decrement functions wrapped with dispatch. I think this is the best and cleanest
//way to seperate your connect and your pure function.
export default connect(
(state) => ({
state => ({
counters: state.app.counters
}),
(dispatch) => ({
dispatch => ({
addNewCounter: () => dispatch(actions.newCounter()),
increment: (id) => dispatch(actions.increment(id)),
decrement: (id) => dispatch(actions.decrement(id)),
incrementWithDelay: (id) => dispatch(actions.incrementWithDelay(id))
increment: id => dispatch(actions.increment(id)),
decrement: id => dispatch(actions.decrement(id)),
incrementWithDelay: id => dispatch(actions.incrementWithDelay(id))
})
)(App)
6 changes: 2 additions & 4 deletions Counters/src/modules/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import app from './app'
import app from './app'

//in this section keep importing yout modules

//and exporting them here
export {
app
}
export { app }

0 comments on commit a8560ad

Please sign in to comment.