This file contains 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 mediaQueryLists = {}; //Add all MediaQueryList object here. | |
const keys = Object.keys(queries); | |
const matches = {}; //contains initial query matches | |
keys.forEach(media => { | |
if (typeof queries[media] === 'string') { | |
/* Adding MediaQueryList object for each and every query to | |
mediaQueryLists object | |
*/ | |
mediaQueryLists[media] = window.matchMedia(queries[media]); |
This file contains 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 React from 'react'; | |
import useBreakpoints from './_customHooks/useBreakpoint'; | |
const App = (props) => { | |
const point = useBreakpoints(); | |
return ( | |
<div> |
This file contains 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, useEffect} from 'react'; | |
import throttle from 'lodash.throttle'; | |
const getDeviceConfig = (width) => { | |
if(width < 320) { | |
return 'xs'; | |
} else if(width >= 320 && width < 720 ) { | |
return 'sm'; | |
} else if(width >= 720 && width < 1024) { | |
return 'md'; |
This file contains 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 getDeviceConfig = (width) => { | |
if(width < 320) { | |
return 'xs' | |
} else if(width >= 320 && width < 720 ) { | |
return 'sm' | |
} else if(width >= 720 && width < 1024) { | |
return 'md' | |
} else if(width >= 1024) { | |
return 'lg' | |
} |
This file contains 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 fs = require('fs'); | |
const readFileAsArray = (fileName, cb = () => {}) => { | |
return new Promise((resolve, reject) => { | |
if(typeof fileName !== 'string') { | |
process.nextTick( | |
cb, | |
new TypeError('Argument should be string') | |
) | |
return reject('Argument should be string') |
This file contains 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 fs = require('fs'); | |
const readFileAsArray = (fileName) => { | |
return new Promise((resolve, reject) => { | |
if(typeof fileName !== 'string') { | |
return reject('Argument should be string') | |
} | |
fs.readFile(fileName, 'utf8', (err, data) => { | |
if(err) { |
This file contains 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
101 | |
102 | |
103 | |
104 | |
105 | |
106 |
This file contains 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 fs = require('fs'); | |
const readFileAsArray = (fileName, cb) => { | |
if(typeof fileName !== 'string') { | |
return process.nextTick( | |
cb, | |
new TypeError('Argument should be string') | |
); | |
} | |
fs.readFile(fileName, 'utf8', (error, data) => { |
This file contains 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 doSomething = (cb) => { | |
let a = Math.random() * 10; | |
if (a < 5) { | |
cb(new Error('Number is Too small')); | |
return; | |
} | |
cb(null, a); | |
}; | |
function callback(error, data) { |
This file contains 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
console.log('main starting'); | |
const a = require('./a.js'); | |
const b = require('./b.js'); | |
console.log('in main, a.done = %j, b.done = %j', a.done, b.done); |