Andrea Giammarchi

Andrea Giammarchi

@webreflection.bsky.social

942 followers32 following201 posts

if you are wondering why this is "as fast as it can be" it's pretty simple: ref.has(k) ? ref.get(k) : (ref.set(k, v), v) checks the map twice for k. This polyfill checks the map twice only if get returned undefined, then it sets anyway so it's 1 check for known keys VS usually 2!

getOrInsertComputed in Map/WeakMap is actually pretty cool, it simplifies caching a lot and it's not limited to synchronous values, example: const cache = new Map; const asText = async page => fetch(page).then(r => r.text()); await cache.getOrInsertComputed('index', asText);

whenever I read posts like "don't us JS Array reduce" I'm like: const gcd = (a, b) => (b ? gcd(b, a % b) : a); const lcm = (a, b) => (a * b) / gcd(a, b); [2, 3, 4, 5].reduce((p, c) => lcm(p, c)); // 60 [12, 18, 36].reduce((p, c) => gcd(p, c)); // 6 I mean ... 🀷

apparently my account has been compromised on bsky ... it's honestly the only service out there that never offered me (until today), or enforced, 2FA, it was kinda inevitable, yet my deepest apologies if my account spam/scammed you by any mean πŸ™

in case anyone is interested, I am documenting what I am working on regularly (each week) with links and every other detail needed to understand where I come from and where I am heading. This is OSS to me, nobody can blame me for not being transparent πŸ˜‡ github.com/WebReflectio...

github.comGitHub - WebReflection/standup: Updates around my OSS contributions.Updates around my OSS contributions. Contribute to WebReflection/standup development by creating an account on GitHub.

in today "nobody asked for it, thanks!" news, the recent issue filed against flatted module (333M downloads per months) kinda "scared" me to the point I rewrote the whole thing in a binary friendly format: flatted-view: please test it, thank you πŸ™ github.com/WebReflectio...

github.comGitHub - WebReflection/flatted-view: Flatted like approach brought to Uint8Array compatible values.Flatted like approach brought to Uint8Array compatible values. - WebReflection/flatted-view

flatted is out with a tiny yet important update for the JS variant: if you stringify 50K objects that point to each other you no longer have call stack recursion error on parse, it just works πŸ₯³

in today "good morning OSS" news, @golang receives its first *flatted* implementation, making flatted now usable in JS, TS, Python, PHP and, ultimately Go πŸ₯³ Huge thank to Harald Fielker for helping out (writing everything), lets' go beyond 300M Downloads! github.com/WebReflectio...

github.comGitHub - WebReflection/flatted: A fast and minimal circular JSON parser.A fast and minimal circular JSON parser. Contribute to WebReflection/flatted development by creating an account on GitHub.

if the channel is *message*, you're all good, if it's *broadcast* you're still good! if it's *xhr* you are on the slow path but it should still work, if it states *async* please let me know what platform/target/OS/device is it so I can investigate/rule that out of the project: πŸ™

today I’ve quickly glued together two libraries that makes custom elements without shadow dom as fast and as simple as it can get and for every browsers … after reading the N post about ShadowDOM issues with CSS. You can stop that madness already πŸ‘‹ github.com/WebReflectio...

github.comGitHub - WebReflection/elements: HTML & SVG Custom Elements.HTML & SVG Custom Elements. Contribute to WebReflection/elements development by creating an account on GitHub.

I’ve fixed a few hiccups here and there, mostly related to the ability to style [is=β€œce-name”] even if created at runtime + ability to automatically create regular custom elements that extend HTML.Element. The /auto variant on CDN lazy load for Safari in less than blink too πŸ₯³

JS Proxy are wonderful, penalized by TS inability to actually understand/deal with these but the things that these unlock are incredible! It might be a niche use case but if you need cached results, here my next go-to library: github.com/WebReflectio...

github.comGitHub - WebReflection/cached-proxy: A cached Proxy with optional timeouts per property to simplify complex remote scenarios.A cached Proxy with optional timeouts per property to simplify complex remote scenarios. - WebReflection/cached-proxy

Andrea Giammarchi reposted

Great, so www.britishairways.com πŸŽ‰ Displays in geo language rather than user language πŸŽ‰ The language picker is at the bottom of a long page πŸŽ‰ The language picker is in the current language, so in order to select "United Kingdom", I need to know what that is in German

cleaning up signals effects automatically on vanilla DOM cases might be tricky ... the fact an inner node contains references to its parent makes it hard to do so via FinalizationRegistry but thanks to Proxy/WeakRef it's possible to make it easy: weaky πŸ₯³ github.com/WebReflectio...

github.comGitHub - WebReflection/weaky: An easy way to avoid leaks.An easy way to avoid leaks. Contribute to WebReflection/weaky development by creating an account on GitHub.

tired of looking for "Open in Browser" links ??? I did create WebJeans and Woom (local only) but the pattern is always the same so I've put an end to this pointless struggle and published regurlator extension: you are in charge, you can redirect anything! github.com/WebReflectio...

github.comGitHub - WebReflection/regurlator: A RegExp URL Redirector.A RegExp URL Redirector. Contribute to WebReflection/regurlator development by creating an account on GitHub.

TIL: if you store in IndexedDB a granted FileSystemX handler you should als store with it options because if you close and reopen the browser, or create a new session, that handler will not work unless you check again against its permissions. Only then it prompts: once or always?

... aaaaand it's gone! Chromium Version 141.0.7390.108 (Official Build) (64-bit) works like a charm (and so does Edge) Chromium Version 141.0.7390.123 (Official Build) (64-bit) wants permissions granted via a resilient user action to reuse a handler it had permissions already 🀦