Skip to content

Instantly share code, notes, and snippets.

@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}.
@dfkaye
dfkaye / onpropertychange-signal-v.5.js
Created November 29, 2023 23:20
onpropertychange signal v.5.js - propertychange events on a node with a mixture of property descriptors and proxy handlers
// 20 September 2023
// onpropertychange signal v.5
// cont'd from https://gist.github.com/dfkaye/428abdeca224c37014d27fc420906d88
// propertychange events on a node with a mixture of property descriptors and
// proxy handlers
// come back to this for the onpropertychange part
// SEE sketch 17 September 2023,
@dfkaye
dfkaye / onpropertychange-signal-v.4.js
Created November 29, 2023 23:17
onpropertychange signal v.4 -- redone form element sketch that works for arrays and objects
// 18 september 2023
// onpropertychange signal v.4
// cont'd from https://gist.github.com/dfkaye/4e06eb749f878662e31a6cb019fbd650
// re-done in less than 30 minutes, this implementation makes more sense and
// works for arrays and objects...
// 19 September 2023
// dispatch propertychange event in deleteProperty handler
@dfkaye
dfkaye / onpropertychange-signal-v.3.js
Created November 29, 2023 23:15
onpropertychange signal v.3- sketch for form element nodes
// 17 September 2023
// onpropertychange signal v.3
// onpropertychange sketch for form element nodes
// cont'd from https://gist.github.com/dfkaye/d849596bdb9e926ad69ad38c974a4763
function N(node) {
var target = node;
@dfkaye
dfkaye / onpropertychange-signal-v.2.js
Created November 29, 2023 23:12
onpropertychange signal v.2 - implementation with proxied objects
// 16 september 2023
// onpropertychange signal v.2
// An implementation with proxied objects.
// cont'd from https://gist.github.com/dfkaye/619c5f31080fce2cd383ac966e132311
////////////////////////////////////////////////////////////////////////////////
// early afternoon