Skip to content

Instantly share code, notes, and snippets.

View tricoder42's full-sized avatar
🕴️
I may be slow to respond.

tricoder42

🕴️
I may be slow to respond.
View GitHub Profile
@tricoder42
tricoder42 / 02_authentication.js
Created June 6, 2017 19:30
2017/06/06 [Medium] Use Selectors in Redux for Great Good
const initialState = {
user: null
}
const getUser = state => state.user
const isAuthenticated = state => Boolean(getUser(state))
@tricoder42
tricoder42 / 01_simple_selector.js
Created June 6, 2017 19:30
2017/06/06 [Medium] Use Selectors in Redux for Great Good
const initialState = {
todos: []
}
const reducer = (state = initialState, action = {}) => {
if (action.type === 'ADD_TODO') {
return {
...state,
todos: [...state.todos, action.payload]
}
@tricoder42
tricoder42 / 01_simple_mapping.js
Last active June 6, 2017 19:30
2017/06/06 [Medium] Use Selectors in Redux for Great Good
const mapStateToProps = (state) => ({
todos: allTodos(state) // instead of state.todos
})
@tricoder42
tricoder42 / react-translated.jsx
Last active November 28, 2016 08:59
What style would you prefer when writing multilingual messages?
// 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
@tricoder42
tricoder42 / actions.js
Created September 5, 2016 16:12
How to react on state changes using redux-saga
// 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, {...}))
}
@tricoder42
tricoder42 / defaultProps.jsx
Last active July 11, 2016 13:34
Default props in React
// Is there any difference? (In performance for example?)
// A: Using default values in object destructuring
const A = ({
value = "",
foo = "bar",
...props
}) => {};
@tricoder42
tricoder42 / Input.jsx
Created November 23, 2015 08:58
Usage of `uncontrollable`
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,
@tricoder42
tricoder42 / .editorconfig
Last active August 29, 2015 14:23
Editor Config
# 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
@tricoder42
tricoder42 / e2e.conf.js
Created December 1, 2014 08:01
Karma/Protractor config files
exports.config = {
allScriptsTimeout: 11000,
specs: [
'e2e/**/*.coffee'
],
multiCapabilities: [
{
// 'browserName': 'Safari'
# BAD:
from production import *
# Good (my personal preference):
from myproject.settings.production import *
# Good (probably your choice):
from .production import *