This file contains hidden or 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 default (state = {}, action) => { | |
| const { type } = action; | |
| const matches = /(.*)_(REQUEST|SUCCESS|FAILURE)/.exec(type); | |
| // not a *_REQUEST / *_SUCCESS / *_FAILURE actions, so we ignore them | |
| if (!matches) return state; | |
| const [, requestName, requestState] = matches; | |
| return { | |
| …state, | |
| // Store whether a request is happening at the moment or not | |
| // e.g. will be true when receiving FETCH_TODOS_REQUEST |
This file contains hidden or 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
| import uuid from 'uuid'; | |
| export default (state = {}, action) => { | |
| const { type, payload } = action; | |
| const matches = /(.*)_(REQUEST|FAILURE)/.exec(type); | |
| // not a *_REQUEST / *_FAILURE actions, so we ignore them | |
| if (!matches) return state; | |
| const [, requestName, requestState] = matches; | |
| return { | |
| …state, | |
| // Store errorMessage |
This file contains hidden or 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 loadingSelector = (state, actions) => { | |
| const types = actions.map(type => { | |
| const matches = /(.*)_(REQUEST|SUCCESS|FAILURE)/.exec(type); | |
| if (!matches) return type; | |
| const [, requestName] = matches; | |
| return requestName; | |
| }); | |
| return types.some(action => state.fetching[action]); | |
| }; |
This file contains hidden or 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 errorByActionSelector = (state = {}, action = '') => { | |
| if (state.errors[action] && state.errors[action].message) { | |
| return { [action]: state.errors[action] }; | |
| } | |
| return undefined; | |
| }; | |
| export const errorsSelector = (state = {}, actions = []) => { | |
| const errors = actions.reduce((accumulator, action) => { | |
| if (errorByActionSelector(state, action)) { |
This file contains hidden or 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 makeActionCreator(type, ...argNames) { | |
| return function(...args) { | |
| const action = { type } | |
| argNames.forEach((arg, index) => { | |
| action[argNames[index]] = args[index] | |
| }) | |
| return action | |
| } | |
| } |
This file contains hidden or 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 createReducer(initialState, handlers) { | |
| return function reducer(state = initialState, action) { | |
| if (handlers.hasOwnProperty(action.type)) { | |
| return handlers[action.type](state, action) | |
| } else { | |
| return state | |
| } | |
| } | |
| } |
This file contains hidden or 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 secureRedirectMiddleware = ({ port, dev }) => (req, res, next) => { | |
| if (!dev && !req.secure) { | |
| const protocol = dev ? 'http' : 'https'; | |
| const portNumber = dev ? `:${port}` : ''; | |
| const url =`${protocol}://${req.hostname}${portNumber}${req.originalUrl}`; | |
| res.redirect(301, url); | |
| } | |
| else { | |
| next(); |
This file contains hidden or 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 secureRedirectMiddleware = ({ dev }) => (req, res, next) => { | |
| if(dev || req.headers['x-forwarded-proto'] === 'https'){ | |
| next(); | |
| } else { | |
| res.redirect(301, `https://${req.hostname}${req.originalUrl}`); | |
| } | |
| }; |
This file contains hidden or 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 array = [ | |
| { id: 1, | |
| name: 'Bob' }, | |
| { id: 2, | |
| name: 'Lucy' }, | |
| { id: 3, | |
| name: 'John' } | |
| ]; | |
| const [first, ...rest] = array; |
This file contains hidden or 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
| { | |
| "root": true, | |
| "plugins": [ | |
| "@nx", | |
| "prettier", | |
| "prefer-arrow", | |
| "simple-import-sort", | |
| "fp-ts-strict", | |
| "fp" | |
| ], |