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
// Promise A+: https://promisesaplus.com/ | |
function MyPromise(fn) { | |
this.status = 'pending'; | |
this.value = null; | |
this.callbacks = []; | |
this.resolve = (newVal) => { | |
const fn = () => { | |
if (this.status !== 'pending') { |
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
function createStore(state, reducer) { | |
const listeners = []; | |
const getState = () => state; | |
const dispatch = (action) => { | |
state = reducer(state, action); | |
listeners.forEach((item) => item()); | |
} |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Concurrent request</title> | |
</head> | |
<body> | |
<button id="fetch">fetch</button> |
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
function shuffle(arr) { | |
if (!arr || arr.length === 0) { | |
return []; | |
} | |
if (arr.length === 1) { | |
return [...arr]; | |
} | |
const map = new Map(); |
OlderNewer