View defaultdict.js
const defaultdict = (getDefault) => | |
new Proxy( | |
{}, | |
{ | |
get: (target, key) => { | |
if (!Reflect.has(target, key)) | |
Reflect.set( | |
target, | |
key, | |
typeof getDefault === "function" ? getDefault() : getDefault |
View memoize.js
let disabled = false; | |
let disabledMap = new WeakMap(); | |
let storage = new WeakMap(); | |
const hasMemoizedProperty = (obj, propName) => { | |
if (!storage.has(obj)) storage.set(obj, {}); | |
const props = storage.get(obj); | |
if (propName in props) return true; | |
return false; | |
}; | |
const getMemoizedProperty = (obj, propName) => { |
View combineRootWithReducers.js
const combineRootWithReducers = ({ | |
root = () => ({}), // reducer which should be on the root level of global state | |
reducers = {}, // other reducers | |
initial = {}, // initial state of global state | |
rootLast = false // if true, root reducer will be called after other reducers | |
}) => { | |
/* | |
this method allows you to combine basic reducers with a reducer which | |
manages state on the root level of global state | |
{ |
View AxiosTokenHelper.js
export class AxiosTokenHelper { | |
/* | |
This helper allows you to cancel old api calls, if new | |
one occurs. | |
const helper = new AxiosTokenHelper(); | |
const callToApi = async (...) => { | |
const source = helper.create(); | |
try { | |
const response = await axios.get( |