Skip to content

Instantly share code, notes, and snippets.

Avatar
🕴️
I may be slow to respond.

Tomáš Ehrlich tricoder42

🕴️
I may be slow to respond.
View GitHub Profile
@tricoder42
tricoder42 / 02_authentication.js
Created Jun 6, 2017
2017/06/06 [Medium] Use Selectors in Redux for Great Good
View 02_authentication.js
const initialState = {
user: null
}
const getUser = state => state.user
const isAuthenticated = state => Boolean(getUser(state))
@tricoder42
tricoder42 / 01_simple_mapping.js
Last active Jun 6, 2017
2017/06/06 [Medium] Use Selectors in Redux for Great Good
View 01_simple_mapping.js
const mapStateToProps = (state) => ({
todos: allTodos(state) // instead of state.todos
})
View HAD_Y2017_M06_D07_Solution.hs
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
/ \
@tricoder42
tricoder42 / 01_fetchSaga.js
Created Jun 13, 2017
2017/06/13 [Medium] redux-saga factories and decorators
View 01_fetchSaga.js
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))
}
}
@tricoder42
tricoder42 / 02_fetchSaga.example.js
Created Jun 13, 2017
2017/06/13 [Medium] redux-saga factories and decorators
View 02_fetchSaga.example.js
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 }
@tricoder42
tricoder42 / 03_fetchSaga.full.js
Created Jun 13, 2017
2017/06/13 [Medium] redux-saga factories and decorators
View 03_fetchSaga.full.js
export const fetchSaga = (entity, api) => function* ({ payload }) {
try {
const data = yield call(api, payload)
yield put(entity.response(data))
}
catch(error) {
// When there's error.response, it's usually response from
// backend server with status 4xx or 5xx.
// No response mostly means there's a connection error, because
// we don't even get anything from server.
@tricoder42
tricoder42 / 04_network_down.js
Last active Jun 13, 2017
2017/06/13 [Medium] redux-saga factories and decorators
View 04_network_down.js
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),
@tricoder42
tricoder42 / 05_auth.js
Created Jun 13, 2017
2017/06/13 [Medium] redux-saga factories and decorators
View 05_auth.js
// Just an example of `isAuthenticated` selector
const selector = {
isAuthenticated: state => state.auth.isAuthenticated
}
export const authRequired = (saga) => function* (action) {
const isAuthenticated = yield select(selector.isAuthenticated)
// If user isn't authenticated, redirect him to /login
if (!isAuthenticated) {
@tricoder42
tricoder42 / bundle.js
Last active Jun 23, 2017
Removing development files from bundle
View bundle.js
// load() call is removed, but import remains there
!function(modules) {
function __webpack_require__(moduleId) {
if (installedModules[moduleId]) return installedModules[moduleId].exports;
var module = installedModules[moduleId] = {
i: moduleId,
l: !1,
exports: {}
};
@tricoder42
tricoder42 / lingui_format.json
Created Sep 1, 2017
jsLingui message catalog formats
View lingui_format.json
{
"Edit": {
"translation": "Upravit",
"origin": [
[
"src/lingui/projects/scenes/Repository/ui/EditableDescription.js",
81
]
]
},
You can’t perform that action at this time.