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 isString = value => typeof value === 'string'; | |
const isSymbol = value => typeof value === 'symbol' | |
const isUndefined = value => typeof value === 'undefined' | |
const isDate = obj => Object.prototype.toString.call(obj) === '[object Date]' | |
const isFunction = obj => Object.prototype.toString.call(obj) === '[object Function]'; | |
const isComplexDataType = value => (typeof value === 'object' || typeof value === 'function') && value !== null; | |
const isValidBasicDataType = value => value !== undefined && !isSymbol(value); | |
const isValidObj = obj => Array.isArray(obj) || Object.prototype.toString.call(obj) === '[object Object]'; | |
const isInfinity = value => value === Infinity || value === -Infinity |
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 proxy(func) { | |
let instance; | |
let handler = { | |
construct(target, args) { | |
if (!instance) { | |
// Create an instance if there is not exist | |
instance = Reflect.construct(func,args) | |
} | |
return instance | |
} |
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 throttle = (func, time = 17, options = { | |
leading: true, | |
trailing: false, | |
context: null | |
}) => { | |
let previous = new Date(0).getTime() | |
let timer; | |
const _throttle = function (...args) { | |
let now = new Date().getTime(); |
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 debounce = (func, time = 17, options = { | |
leading: true, | |
context: null | |
}) => { | |
let timer; | |
const _debounce = function (...args) { | |
if (timer) { | |
clearTimeout(timer) | |
} | |
if (options.leading && !timer) { |
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 { | |
--primary-color-h: 156; | |
--primary-color-s: 50%; | |
--primary-color-l: 50%; | |
--primary-color: hsl(var(--primary-color-h), var(--primary-color-s), var(--primary-color-l)); | |
--primary-color--light: hsl(var(--primary-color-h), var(--primary-color-s), calc(var(--primary-color-l) + var(--lighten))); | |
--primary-color--dark: hsl(var(--primary-color-h), var(--primary-color-s), calc(var(--primary-color-l) + var(--darken))); | |
--secondary-color: hsl(calc(var(--primary-color-h) + 180), var(--primary-color-s), var( --primary-color-l)); | |
--lighten: 15%; | |
--darken: -15%; |
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
// ensure the keys being passed is an array of key paths | |
// example: 'a.b' becomes ['a', 'b'] unless it was already ['a', 'b'] | |
const keys = ks => Array.isArray(ks) ? ks : ks.split('.') | |
// traverse the set of keys left to right, | |
// returning the current value in each iteration. | |
// if at any point the value for the current key does not exist, | |
// return the default value | |
const deepGet = (o, kp, d) => keys(kp).reduce((o, k) => o && o[k] || d, o) |
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 union(setA, setB) { | |
var _union = new Set(setA); | |
for (var elem of setB) { | |
_union.add(elem); | |
} | |
return _union; | |
} | |
function intersection(setA, setB) { |
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 createStore = (reducer, initialState = {}, middlewares = []) => { | |
let state = initialState; | |
const listeners = []; | |
// final step - call the reducer and invoke the listeners | |
let finalMiddleware = (action) => { | |
state = reducer(state, action); | |
listeners.forEach(listener => listener()); | |
return state; | |
} |