View useAsyncEffect.tsx
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 { useEffect } from 'react'; | |
type EffectReturn = Promise<(() => void) | void>; | |
type EffectFunction = (ignore: { current: boolean }) => EffectReturn; | |
type DependencyArray = unknown[]; | |
/** | |
* Works like useEffect, but accepts an async function as the effect | |
* function and provides an ignore object with a current attribute | |
* that tells if you should ignore the result. |
View rewrite.js
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
/** | |
* Check the following example in jsfiddle. | |
* | |
* <https://jsfiddle.net/qg9k3pmo/1/> | |
*/ | |
/** | |
* Rewrite 'el' element periodically with a string composed by an | |
* always static 'base' string and slices of 'sentence' in order | |
* to create a console prompt writing effect. For example, if: |
View httpGet.js
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
// Variable to track requests and their callbacks so that httpGet() | |
// does not make a request to the same URL if the previous has not | |
// finished. | |
var requests = {}; | |
/** | |
* Fetches data from a JSON API through HTTP GET (XMLHttpRequest). | |
* | |
* Requests to the same URL before the previous one completes are | |
* coalesced and their callbacks receive the same result. |
View anchorify.js
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
/** | |
* Looks for URLs in the source text and replaces them with anchor | |
* tags. If there are no links in the text, it does nothing. | |
* | |
* @param {String} text Source text. | |
* | |
* @return {String} New string with URLs in the source | |
* text replaced with anchor tags. | |
*/ | |
function anchorify(text) { |