Skip to content

Instantly share code, notes, and snippets.

View WebReflection's full-sized avatar
🎯
Focusing

Andrea Giammarchi WebReflection

🎯
Focusing
View GitHub Profile
class WeakValue extends Map {
#registry = new FinalizationRegistry(key => {
if (this.has(key) && !this.get(key).deref())
this.delete(key);
});
get(key) {
const value = super.get(key);
return value && value.deref();
}
set(key, value) {
class Signal extends EventTarget {
#aborted = false;
constructor(controller) {
super();
// one of those cases where unreachable listener
// is actually desired 'cause it's more secure
this.addEventListener('abort', event => {
if (event.detail !== controller)
event.stopImmediatePropagation();
else
class Signal extends EventTarget {
#aborted = false;
#controller = null;
constructor(controller) {
super();
this.#controller = controller;
this.addEventListener('abort', this);
}
handleEvent(event) {
if (event.detail !== this.#controller)
customElements.define('any-element', class extends Element {
get data() {
return this.dataset;
}
set data(value) {
// more or less this operation, but previously known keys,
// not found in value, should be dropped from the dataset
Object.assign(this.dataset, value);
}
get aria() {
@WebReflection
WebReflection / dom-libraries.md
Last active February 24, 2025 11:28
A recap of my FE / DOM related libraries

My FE/DOM Libraries

a gist to recap the current status, also available as library picker!

Minimalistic Libraries

do one thing only and do it well

  • µhtml (HTML/SVG auto-keyed and manual keyed render)
  • augmentor (hooks for anything)
  • wickedElements (custom elements without custom elements ... wait, what?)
@WebReflection
WebReflection / handle-event-doodle.md
Last active July 25, 2024 10:58
The `handleEvent` ASCII doodle

About This Gist

This gist summarizes the handleEvent(event) pattern features, something standard, something described by me many times, written in my tiny book, tweeted about, and yet it's something most Web developers ignore.

The handleEvent ASCII Doodle

                  ┌---------------------------------┐
var handler = {   | any object that inherits or     |
@WebReflection
WebReflection / local-storage-vs-compression.js
Created February 19, 2020 08:59
A benchmark to see how many items can be stored using WebCompressor
const findLimit = async (type, create) => {
console.log(
`%c ${type} benchmark `,
`font-weight:bold;color:white;background-color:black`
);
localStorage.clear();
let i = 0;
let length = 0;
while (true) {
try {
@WebReflection
WebReflection / how-to-file-a-github-issue.md
Created November 25, 2019 19:34
How to file a GitHub/Lab issue

How to file a GitHub/Lab issue

helping each others


Original Medium post


Filing an issue is not about delegating your problem to another developer, it’s about helping maintainers solve issues they haven’t encountered yet.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>A Static Email Form Example + reCAPTCHA</title>
<link rel="stylesheet" href="css/index.css">
<script defer src="//unpkg.com/static.email"></script>
<script defer src="js/index.js"></script>
<!-- this script, after all others, will bring in reCAPTCHA -->
// nullify the global reference while instrumenting the form
StaticEmail = (function (StaticEmail) {
// we don't know when window.recaptcha will be called,
// so we use a promise to simplify our workflow
var captcha = new Promise(function (resolve) {
window.recaptcha = function () {
// resolve passing the widget id along
resolve(
grecaptcha.render('recaptcha', {
// the SITE KEY reCAPTCHA provided