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, { createContext, useReducer, useContext, Fragment } from 'react'; | |
import './App.css'; | |
const authReducer = (state, action) => { | |
switch (action.type) { | |
case 'increment': | |
return { | |
...state, | |
age: state.age + 1 | |
}; |
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
let nowTop = 0; | |
const bodyEl = document.body; | |
export default mute => { | |
if (mute) { | |
nowTop = window.scrollY; | |
bodyEl.style.position = 'fixed'; | |
bodyEl.style.top = -nowTop + 'px'; | |
} else { |
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 fse = require('fs-extra'); | |
const path = require('path'); | |
const isNotDot = (filepath) => { | |
const REG = /^\..+/i; | |
return !REG.test(filepath); | |
}; | |
/** | |
* calculate the relative path from `start` to `end` |
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
process.stdin.resume(); | |
process.stdin.setEncoding('ascii'); // 'utf-8' also supported | |
let _input = ""; | |
process.stdin.on('data', function (data) { | |
_input += data; | |
}); | |
process.stdin.on('end', function () { |
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
/** | |
The zero-width space character is encoded in Unicode as U+200B ZERO WIDTH SPACE (HTML ​) | |
*/ | |
function insertSpaces(string){ | |
return Array.from(string).join('\u200b'); | |
} | |
// see more at https://en.wikipedia.org/wiki/Zero-width_space | |
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 NoopPromise = { | |
then: () => NoopPromise, | |
catch: () => NoopPromise, | |
}; | |
Promise.resolve().then(() => { | |
const number = Math.random(); | |
if (number > 0.5) { | |
return number; | |
} |
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
debugger; | |
var a; | |
if (true) { | |
a = {a: 2}; | |
function a() {} | |
a.ot = '9'; | |
a = {a: 4}; | |
console.log('1', a); |
For those JavaScript programmers, event loop is an important concept, inevitably.
Literally, event loop is what JavaScritp uses to implement non-blocking execution. Understanding how the event loops works internally would benefit you a lot when programming in JavaScript.
There are two major environments JavaScript runs in: browser and Node.js.