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
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
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 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 = { | |
user: { | |
name: 'anonymous', | |
token: null | |
} | |
} | |
const getUser = state => state.user || {} | |
const isAuthenticated = state => Boolean(getUser(state).token) | |
const isAnonymous = state => !isAuthenticated(user) |
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 reducer = ... | |
const ID = 'auth' | |
const local = state => state[ID] | |
const getUser = state => local(state).user | |
const isAuthenticated = state => Boolean(getUser(state)) | |
export default {[ID]: reducer} |
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
module Y2017.M06.D07.Exercise where | |
{-- | |
So, here's one of the questions Amazon asks developers to test their under- | |
standing of data structures. | |
You have a binary tree of the following structure: | |
A | |
/ \ |
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
export const fetchSaga = (entity, api) => function* ({ payload }) { | |
try { | |
const data = yield call(api, payload) | |
yield put(entity.response(data)) | |
} | |
catch(error) { | |
yield put(entity.response(error)) | |
} | |
} |
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
function ApiGetUser({ id }) { | |
return fetch(url`/user/${id}`) | |
} | |
// Just an example. Action creators are usually | |
// created using `createAction` from `redux-actions` | |
const getUser = { | |
request: (id) => ({ | |
type: 'USER_GET@REQUEST', | |
payload: { id } |
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
export function* checkConnection () { | |
let interval = 1 | |
// eslint-disable-next-line no-constant-condition | |
while (true) { | |
// race == wait for effect which comes first | |
const { timeout, up } = yield race({ | |
// ping triggered manually | |
// e.g: 'reconnect now' button | |
ping: take(action.networkPing), |