A 15-Line Proxy That Tells You Exactly What Changed
Dirty checking, undo history, "unsaved changes" warnings - all reduce to knowing when an object changed. Proxy intercepts the writes themselves, no framework needed.
Software Engineer
I build web applications and share what I learn along the way.
Step-by-step programming tutorials on PHP, JavaScript, Laravel, WordPress and more.
Dirty checking, undo history, "unsaved changes" warnings - all reduce to knowing when an object changed. Proxy intercepts the writes themselves, no framework needed.
Store state against DOM nodes, cache per-object computations, keep private data - WeakMap does all three and lets the garbage collector clean up behind you.
Async generators hide the pagination bookkeeping - cursors, hasMore flags, page counters - behind a clean loop that fetches pages only as you consume them.
Promise.all fails everything when one request dies - usually not what a dashboard wants. The other three combinators cover the cases all() gets wrong.
sort() silently rearranges the original array - a bug factory in shared state. ES2023 shipped non-mutating twins for the worst offenders, plus with() for single-item replacement.
Python has range(), PHP has range() - JavaScript has a weird-looking idiom that does the same and more, once you understand why the mapping callback is built in.
ES2021 added three assignment operators that collapse the most common if-statements in JavaScript. Knowing when ??= beats ||= is the part that matters.
fetch() still cannot report upload progress reliably - but XMLHttpRequest has done it for fifteen years. The full pattern: progress events, a PHP receiver, and the config limits that silently break big uploads.
Stop wiring loading states into every request. jQuery broadcasts global AJAX lifecycle events, and $.ajaxSetup injects headers everywhere - CSRF tokens included.
jQuery lets you define custom pseudo-selectors - :external, :blank, :offscreen - that work in every $() call, filter() and delegation rule in your codebase.
Buttons work until the list refreshes over AJAX, then silently stop. Delegated events fix it permanently - and the same pattern is two lines in vanilla JS.
WebSockets need infrastructure. Polling hammers your server. SSE streams live updates over normal HTTP with a PHP file and the built-in EventSource API - reconnection included.