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 immutableMap = Immutable.fromJS({ a: 1, b: 2 }) | |
const { a, b } = immutableMap | |
console.log(a) // undefined | |
console.log(b) // undefined |
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 immu = obj => deepFreeze(obj) | |
const createNewState = (currentState, updater) => { | |
const draftState = deepUnfreeze(currentState) | |
updater(draftState) | |
return immu(draftState) | |
} | |
export { immu, createNewState } |
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 initialState = { | |
todos: { | |
'a': { id: 'a', description: '...', isComplete: false }, | |
'b': { id" 'b', description: '...', isComplete: false } | |
} | |
} | |
const reducer = (state, action) => ({ | |
...state, | |
todos: { |
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 { createAction, createReducer } from 'redux-toolkit' | |
import { initialState } from 'the-gist-above' | |
// Another utility from the toolkit - createAction | |
const toggleTodo = createAction('increment') | |
const reducer = createReducer(initialState, { | |
[toggleTodo]: (state, action) => { | |
state.todos[action.todoId].isComplete = action.payload | |
} |
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
useEffect(() => { | |
const fetchShops = async () => { | |
try { | |
const shops = await axios.get(process.env.GATSBY_COFFEE_SHOPS_URL) | |
setShops(shops.data.Items) | |
} catch (err) { | |
setShopsError(true) | |
} finally { | |
setShopsLoading(false) | |
} |
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
// gatsby-node.js file | |
const axios = require('axios') | |
require('dotenv').config({ | |
path: `.env.${process.env.NODE_ENV}`, // this dotenv config gives access to process.env object | |
}) | |
const getCoffeeShops = async () => { | |
const shops = await axios.get(process.env.GATSBY_COFFEE_SHOPS_URL) | |
return shops.data.Items |
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
app.post('/getData', (req, res) => { | |
res.send(generateData(User)); | |
}); | |
app.post('/getFlyWeightData', (req, res) => { | |
res.send({ data: generateData(FlyWeightUser), EXTRA_STATIC_DATA }) | |
}); |
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
chrome.webRequest.onBeforeRequest.addListener( | |
request => { | |
const url = new URL (request.url) | |
url.searchParams.set('tag', 'MY_REFERRAL_TAG') | |
return { | |
redirectUrl: url.toString() | |
} | |
}, | |
{ urls: ['https://amazon.co.uk/*] }, ['blocking'] | |
) |
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 { useState } from 'react'; | |
const useFetch = (fetchRequest, fetchName = 'is') => { | |
const [isLoading, setIsLoading] = useState(false); | |
const [isError, setIsError] = useState(false); | |
const [isSuccess, setIsSuccess] = useState(false); | |
const [fetchResponse, setFetchResponse] = useState(null); | |
const resetFetchState = () => { | |
setIsLoading(false); |
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 { createContext, useReducer, useContext } from 'react'; | |
import { bindActionCreators } from '~/context/utils'; | |
const initialState = { | |
modalOpen: null, | |
}; | |
const actionTypes = { | |
OPEN_MODAL: 'OPEN_MODAL', | |
CLOSE_MODALS: 'CLOSE_MODALS', |