A tiny ~150-byte polyfill for Promise.prototype.finally
.
Useful for browsers that support Promise but not the .finally()
method.
npm install finally-polyfill
// This is a proper alternative to | |
// https://github.com/BuckleScript/bucklescript/blob/b9508105b1a35537bdea9a1fabd10f6c65f776b4/jscomp/bsb/templates/react-hooks/src/FetchedDogPictures/FetchedDogPictures.re#L14 | |
// The one in that file uses Promise, but that's *wrong*. | |
// We only used promise as a demo of its API. We'll remove it soon. | |
// As you can see below, the pure XMLHttpRequest code is just as clean, | |
// less mysterious for all, more performant, extensible, and actually correct. | |
// Ignore these externals for now. They're just for illustration | |
// purposes. I just copy pasted the Js code from |
const express = require('express'); | |
const app = express(); | |
// Application | |
app.get('/', function(req, res) { | |
if (process.env.NODE_ENV === 'development') { | |
for (var key in require.cache) { | |
delete require.cache[key]; | |
} | |
} |
const MY_DOMAIN = "agodrich.com" | |
const START_PAGE = "https://www.notion.so/gatsby-starter-notion-2c5e3d685aa341088d4cd8daca52fcc2" | |
const DISQUS_SHORTNAME = "agodrich" | |
addEventListener('fetch', event => { | |
event.respondWith(fetchAndApply(event.request)) | |
}) | |
const corsHeaders = { | |
"Access-Control-Allow-Origin": "*", |
%GetOptimizationStatus
return a set of bitwise flags instead of a single value,
to access the value, you need to take the binary representation of the returned value.
Now, for example, if 65
is returned, the binary representation is the following:
(65).toString(2).padStart(12, '0');
// 000001000001
Each binary digit acts as a boolean with the following meaning:
/* | |
Let's Assume we want to have a Functor which creates a new Module from | |
a specific Component Model | |
The Functor recieves another Module named `Component`, which needs to satisfy certain constraints: | |
- Component requires an abstract type t (no matter what concrete type) | |
- It also needs to implement a `render` function which gets said type t and returns a `string` | |
Also, the newly created module will then contain a function `doSomething`, which will handle any | |
instance of `Component.t`. So our `Component` also will need a function to create an instance for that, |
This is the second article in a series of articles around Rusts new async/await
feature. The first article about interfaces can be found
here.
In this part of the series we want to a look at a mechanism which behaves very
different in Rust than in all other languages which feature async/await
support. This mechanism is Cancellation.
4 years after
after the release of Rust 1.0, it seems like Rust is now finally getting close
to getting support for async/await
- a language feature which aims to make it
easier to write programs in an asynchronous fashion (where multiple logical
tasks get multiplexed on a lower number of OS threads).
One of the last steps before the feature is stabilized is choosing the best possible syntax. The discussions around syntax have triggered an enormous
~80b ponyfill for String.prototype.replaceAll() with good performance.
Why ponyfill? Because this is a proposal for a spec, and polyfilling it in-place before it gets solidified could break code that relies on an incorrect implementation.
/** | |
`useChangeLog` - dev-mode helper hook to let you | |
know why a memoized component re-rendered! | |
Usage example: | |
const YourComponent = React.memo((props) => { | |
// Just drop this fella into your memo component's body. | |
useChangeLog(props); |