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
export default async ( | |
...promises | |
) => { | |
return (await Promise.race([ | |
Promise.all(promises), | |
Promise.all([promises]) | |
]))[0] !== promises | |
} |
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 { assign, create, freeze } = Object | |
const contexts = new Map() | |
export const capture = true | |
export const once = true | |
export const passive = true | |
export const context = (listener, event) => { | |
const { currentTarget, target, type } = event |
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 registry = new FinalizationRegistry(handler => handler.disconnect()) | |
class EventHandler { | |
#consumed = false | |
#options = null | |
#prevent = false | |
#promises = [] | |
#resolve = null | |
#ref = null | |
#type = null |
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
export class MutationObserver extends globalThis.MutationObserver { | |
#consumed = false | |
#promises = [] | |
#resolve = null | |
#enqueue = record => { | |
if (this.#resolve) { | |
this.#resolve(record) | |
this.#next() | |
} |
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
export default new Proxy(new Map(), { | |
get: (target, name) => { | |
if (!target.has(name)) { | |
target.set(name, [[]]) | |
} | |
const entry = target.get(name) | |
const [resolvers, value] = entry | |
return entry.length === 2 |
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
import * as fetcher from './text-fetcher.js' | |
const fetchText = event => fetcher.resolver.resolve(event) | |
document.querySelector('form') | |
.addEventListener('submit', fetchText) | |
document.querySelector('a') | |
.addEventListener('click', fetchText) |
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
import { resolve, text } from './fetcher.js' | |
const fetchText = event => resolve(event, [ | |
fetch, | |
text, | |
data => console.log({ data }) | |
]) | |
document.querySelector('form') | |
.addEventListener('submit', fetchText) |
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 fileToURI = async file => new Promise((onload, onerror) => | |
Object.assign(new FileReader(), { onload, onerror }) | |
.readAsDataURL(file)) |
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* controller (end) { | |
let progress = 0 | |
while (1) { | |
const value = yield progress | |
if (value === end) { | |
break | |
} | |
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* controller (end) { | |
while (end !== (yield)) {} | |
} | |
const end = Symbol() | |
const it = controller(end) | |
console.log(it.next()) // { value: undefined, done: false } | |
console.log(it.next(end)) // { value: undefined, done: true } -> aborted |
NewerOlder