Skip to content

Instantly share code, notes, and snippets.

@dfkaye
dfkaye / forms-elements-access-patterns.js
Created February 16, 2024 06:28
many ways to access forms and elements in the DOM
// 15 February 2024
// many ways to access forms and elements in the DOM
var input = document.createElement("input");
input.name = "E";
var form = document.createElement("form");
form.name = "F";
form.appendChild(input);
document.body.appendChild(form);
@dfkaye
dfkaye / shadow-dom-mutation-benchmark.js
Last active December 12, 2023 22:20
Shadow DOM mutation benchmark: How long does it take to update the Shadow DOM?
// 12 December 2023
// Shadow DOM mutation benchmark
// How long does it take to update the Shadow DOM?
// Successor to "How long does it take to update the DOM?" gist at
// https://gist.github.com/dfkaye/6ceef75ee61892428ef09b3b67138cd5
// In this test, as before, we create a table with a tbody, 1000 rows (<tr>),
// where each row contains 4 cells (<td>), and perform updates on all 4000 cells
@dfkaye
dfkaye / dom-mutation-benchmark.js
Last active December 12, 2023 22:19
DOM mutation benchmark: How long does it take to update the DOM?
// 11 December 2023
// DOM mutation benchmark
// How long does it take to update the DOM?
// Continued by "How long does it take to update the Shadow DOM?" gist at
// https://gist.github.com/dfkaye/1c4068e05b5d891a394d8c97fbe87684
// When it comes to those fastest DOM mutation framework benchmarks, ask how
@dfkaye
dfkaye / dynamic-exit-condition-convergence-test.js
Created November 30, 2023 00:04
convergence test for pseudo-stochastic monte carloesque dynamically updated loop exit condition
// 21 November 2023
// convergence test for pseudo-stochastic monte carloesque dynamically updated
// loop exit condition
// program proof that loops with changing random length converge on square root
// of max length (from a Tweet the other day that jonathan blow responded to).
// T asked why programmers think a loop with length reset to random * 100 will
// average to 50 instead of 10 (well, actually, it will converge on the square
// root of max plus 2, given the first two steps always execute).
@dfkaye
dfkaye / whats-in-an-array.js
Last active March 22, 2024 07:09
What's "in" an array?
// 29 September 2023
// What's in an array?
// Here's an array:
var a = [1,2,3,4];
// If we use want only the *own* properties of an array, we can use the
// Object.keys() method to inspect it.
@dfkaye
dfkaye / collect-comment-text-attribute-childnodes.js
Created November 29, 2023 23:52
Collect a node's Comment, Text, and Attribute child nodes
// 21 September 2023
// Collect a node's Comment, Text, and Attribute child nodes
// should break this up into separate functions focused on node type
// then find items by their nodeValue
function collect(node) {
var comments = [];
var text = [];
var attributes = [];
@dfkaye
dfkaye / onpropertychange-signal-v.9.js
Last active April 14, 2024 06:30
onpropertychange signal v.9 -- Success! v.9 supports both Object and EventTarget
// 27 September 2023
// onpropertychange signal v.9
// cf. v.8 https://gist.github.com/dfkaye/548622151971122110bf4047ae3ac432
// and v.1 https://gist.github.com/dfkaye/619c5f31080fce2cd383ac966e132311
// Success, at last! v.9 supports both Object and EventTarget.
// Investigating where proxy on an array allows array.push mutations, the goal
// here was to get the proxy to work on EventTarget and Object, this time with
@dfkaye
dfkaye / onpropertychange-signal-v.8.js
Created November 29, 2023 23:37
onpropertychange signal v.8 -- trying to simplify the prototype stack
// 26 September 2023
// onpropertychange signal v.8
// cont'd from https://gist.github.com/dfkaye/3affad4c43e363a84ac4320eae375129
// Going back to v.1 prototype enhancement/pollution, (see
// https://gist.github.com/dfkaye/619c5f31080fce2cd383ac966e132311), trying to
// simplify the prototype stack.
// The signals and delegate properties are assigned on the target using the
@dfkaye
dfkaye / onpropertychange-signal-v.7.js
Created November 29, 2023 23:33
onpropertychange signal v.7 -- method delegation in the proxy `get` handler
// 22 September 2023
// onpropertychange signal v.7
// cont'd from https://gist.github.com/dfkaye/1d9a55b8fe6659df7ba7c04edbd24bf7
// Another one that seems to work (we get events from Array changes) but my
// reasoning in the comments seems hand-wavingly suspect.
// Method delegation adds more setup time (iterating and so on), another mapping
// dependency, and copying the prototype and setting that as the new prototype
@dfkaye
dfkaye / onpropertychange-signal-v.6.js
Created November 29, 2023 23:22
onpropertychange signal v.6 - more problems between descriptors and proxies
// 21 September 2023
// onpropertychange signal v.6 already
// cont'd from https://gist.github.com/dfkaye/dae6958adf813735d9154be23a0ebb09
// Still not happy but we have better support across types of objects (only
// element, text, object, and array so far).
// After all that, Object.defineProperty on property names is enough to ensure
// related property updates, e.g., {textContent, nodeValue, data, wholeText}.