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
const initialState = { | |
user: null | |
} | |
const getUser = state => state.user | |
const isAuthenticated = state => Boolean(getUser(state)) |
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
const initialState = { | |
todos: [] | |
} | |
const reducer = (state = initialState, action = {}) => { | |
if (action.type === 'ADD_TODO') { | |
return { | |
...state, | |
todos: [...state.todos, action.payload] | |
} |
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
const mapStateToProps = (state) => ({ | |
todos: allTodos(state) // instead of state.todos | |
}) |
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
// message is constructed using helper functions | |
const HelperFunction = ({count}) => | |
<Trans> | |
{plural(count, { | |
one: "One glass", | |
other: "# glasses" | |
})} or wine | |
</Trans> | |
// message written using template literals |
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
// just a helper function | |
const updateComponent = (component, newState) => component.setState(newState) | |
// 1st approach using redux-promise. Actions returns promises, so component | |
// can trigger actions when promise is resolved. | |
const handleEventPromise = (props) => (event) => { | |
this.props.action({...}) | |
.then((payload) => updateComponent(this, {...})) | |
} |
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
// Is there any difference? (In performance for example?) | |
// A: Using default values in object destructuring | |
const A = ({ | |
value = "", | |
foo = "bar", | |
...props | |
}) => {}; | |
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
const PureInput = React.createClass({ | |
propTypes: { | |
name: React.PropTypes.string.isRequired, | |
label: React.PropTypes.string, | |
type: React.PropTypes.string, | |
placeholder: React.PropTypes.string, | |
// value/callback pair | |
value: React.PropTypes.string, |
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
# top-most EditorConfig file | |
root = true | |
# Unix-style newlines with a newline ending every file | |
[*] | |
charset = utf-8 | |
end_of_line = lf | |
insert_final_newline = true | |
trim_trailing_whitespace = true |
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
exports.config = { | |
allScriptsTimeout: 11000, | |
specs: [ | |
'e2e/**/*.coffee' | |
], | |
multiCapabilities: [ | |
{ | |
// 'browserName': 'Safari' |
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
# BAD: | |
from production import * | |
# Good (my personal preference): | |
from myproject.settings.production import * | |
# Good (probably your choice): | |
from .production import * |