-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an example for components connected to Redux state
- Loading branch information
Showing
28 changed files
with
186 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Project | ||
web/js/bundle.* | ||
|
||
# Node | ||
logs | ||
*.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as types from './types'; | ||
|
||
export const helpRequested = () => { | ||
return { | ||
type: types.HELP_REQUESTED | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const HELP_REQUESTED = 'HELP_REQUESTED'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
import AbstractAboutButtonContainer from './AbstractAboutButtonContainer'; | ||
|
||
export default class AboutButtonContainer extends AbstractAboutButtonContainer { | ||
onClick() { | ||
alert('This is an example application to show how to reuse code between React and React Native'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import { Alert } from 'react-native'; | ||
|
||
import AbstractAboutButtonContainer from './AbstractAboutButtonContainer'; | ||
|
||
export default class AboutButtonContainer extends AbstractAboutButtonContainer { | ||
onClick() { | ||
Alert.alert('This is an example application to show how to reuse code between React and React Native'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import React from 'react'; | ||
|
||
export default props => | ||
<button className="button" onClick={props.onClick}> | ||
About | ||
</button>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import Button from 'react-native-button'; | ||
|
||
import styles from '../../native/styles'; | ||
|
||
export default props => | ||
<Button | ||
onPress={props.onClick} | ||
style={styles.buttonText} | ||
containerStyle={styles.button}> | ||
About | ||
</Button>; |
23 changes: 23 additions & 0 deletions
23
app/components/AboutButton/AbstractAboutButtonContainer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import AboutButtonView from './AboutButtonView'; | ||
|
||
export default class AbstractAboutButtonContainer extends React.Component { | ||
constructor(props) { | ||
// new.target is not working on Android | ||
// if (new.target === AbstractAboutButtonContainer) { | ||
// throw new TypeError('Cannot construct AbstractAboutButtonContainer instances directly'); | ||
// } | ||
|
||
super(props); | ||
|
||
this.onClick = this.onClick.bind(this); | ||
} | ||
|
||
onClick() { | ||
throw new TypeError('Abstract method onClick is not implemented'); | ||
} | ||
|
||
render() { | ||
return <AboutButtonView onClick={this.onClick}/>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import AboutButtonContainer from './AboutButtonContainer'; | ||
export default AboutButtonContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import React from 'react'; | ||
|
||
import Title from '../Title'; | ||
import AboutButton from '../AboutButton'; | ||
import HelpButton from '../HelpButton'; | ||
|
||
export default () => | ||
<div className="container"> | ||
<Title/> | ||
<AboutButton/> | ||
<HelpButton/> | ||
</div>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
|
||
import store from '../../store'; | ||
import AppView from './AppView'; | ||
export default AppView; | ||
|
||
export default class AppContainer extends React.Component { | ||
render() { | ||
return ( | ||
<Provider store={store}> | ||
<AppView/> | ||
</Provider> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React from 'react'; | ||
|
||
export default props => | ||
<button className="help-button" onClick={props.onClick}> | ||
<button className="button" onClick={props.onClick}> | ||
Help | ||
</button>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,26 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
|
||
import { helpRequested } from '../../actions/help-actions' | ||
import { getHelpRequestsNumber } from '../../reducers'; | ||
import HelpButtonContainer from './HelpButtonContainer'; | ||
export default HelpButtonContainer; | ||
|
||
class HelpButton extends React.Component { | ||
render() { | ||
return ( | ||
<HelpButtonContainer { ...this.props }/> | ||
) | ||
} | ||
} | ||
|
||
HelpButton.propTypes = { | ||
helpRequests: PropTypes.number.isRequired, | ||
helpRequested: PropTypes.func.isRequired, | ||
}; | ||
|
||
const mapStateToProps = store => ({ | ||
helpRequests: getHelpRequestsNumber(store), | ||
}); | ||
|
||
export default connect(mapStateToProps, { helpRequested })(HelpButton) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as types from '../actions/types'; | ||
|
||
const initialState = { | ||
requests: 0, | ||
}; | ||
|
||
export default function(state = initialState, action) { | ||
switch (action.type) { | ||
case types.HELP_REQUESTED: | ||
return {requests: state.requests + 1}; | ||
|
||
default: return state; | ||
} | ||
}; | ||
|
||
export const getRequestsNumber = state => state.requests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { combineReducers } from 'redux'; | ||
|
||
import help, * as helpSelectors from './help'; | ||
|
||
export default combineReducers({ | ||
help, | ||
}); | ||
|
||
export const getHelpRequestsNumber = store => helpSelectors.getRequestsNumber(store.help); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createStore } from 'redux'; | ||
import reducers from './reducers'; | ||
|
||
export default createStore(reducers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.