Skip to content

Instantly share code, notes, and snippets.

@dfkaye
dfkaye / event-target-signal.js
Created August 22, 2023 21:43
A signal() method attached to nodes and text
// 14-21 August 2023
// A signal method attached to nodes and text.
// Continuation of the debate in the "dom" tests at the end of the signal.js
// gist, at https://gist.github.com/dfkaye/fe7b210c62b82faf4bffd5092dd41653.
// If a signal change updates a node property, it turns out there are several
// co-dependencies to manage - meaning, we have to update other content
// properties manually.
@dfkaye
dfkaye / control.target.js
Created August 5, 2023 05:01
Control is a constructor with an EventTarget field that manages events and listeners of different types (so we don't have to).
// 4 August 2023
// control.target.js
// Control is a constructor with an EventTarget field that manages events and
// listeners of different types (so we don't have to).
// Compare with control.signal.js at https://gist.github.com/dfkaye/8701a2d416556aab68da7519b2c5429a
// Prototype adds decorator API for adding, removing, and dispatching events.
@dfkaye
dfkaye / control.signal.js
Last active August 5, 2023 05:01
Control is a constructor with a 'signal' Map containing different 'types' of event callbacks.
// 4 August 2023
// control.signal.js
// Control is a constructor with a 'signal' Map containing different 'types' of
// event callbacks.
// Similar to EventTarget, but that's coming in the next post at
// https://gist.github.com/dfkaye/f773b85fabf661108ed4ff7a2cdfc61d
// Prototype adds decorator API for adding, removing, and dispatching events.
@dfkaye
dfkaye / EventTarget-in-worker-test.js
Created August 4, 2023 19:15
EventTarget is available in Worker contexts
// 3 August 2023
// Yes, EventTarget is available in Worker contexts,
// although not yet convinced that we need them there.
// Incidentally, in 2023, Google (and probably Microsoft) has
// decided to make Chrome The Most Hostile Environment for web
// development, particularly in the console both in regular and
// private/incognito windows with unpublicized Content Security
// Policy headers for "trusted HTML", "trusted src", etc.
@dfkaye
dfkaye / set.toJSON.js
Created August 2, 2023 19:35
polyfill to support serializing a JS Set
// 2 August 2023
// set.toJSON
// when you absolutely must serialize a set
// using JSON.stringify() which normally
// returns set: {}
Set.prototype.toJSON = function toJSON() {
var set = {};
for (var [k, v] of this.entries()) {
set[k] = v;
@dfkaye
dfkaye / map.toJSON.js
Created August 2, 2023 19:29
polyfill to support JSON.stringify over JS Maps
// 1 August 2023
// map.toJSON
// when you absolutely must serialize a map
// using JSON.stringify() which normally
// returns map: {}
Map.prototype.toJSON = function toJSON() {
var map = {};
for (var [k, v] of this.entries()) {
map[k] = v;
@dfkaye
dfkaye / tweet-one-line.js
Created August 2, 2023 19:28
tweet, "one line of code"
// 22 July 2023
// one line tweet
// https://twitter.com/dfkaye/status/1682924372775038979
// response to @johanvinet
// "PROGRAMMERS you can only use one line of code to convince people to follow
// you"
// Of course no new followers...
console.log(
`%c${$('body').innerHTML = await (async v => v)(
@dfkaye
dfkaye / signal.final.js
Last active August 22, 2023 22:52
signal - implemented as a reactive-observable but not like a hook...
// 21 July 2023
// A signal implementation as a "reactive-observable" value with listeners and
// dispatch-notify behavior.
// This is not equivalent to the ReactJS hooks pattern or SolidJS signals.
// We're looking for a way to make nested data reactive so we notify changes by
// paths in the structure... the usual pipedream...
////////////////////////////////////////////////////////////////////////////////
@dfkaye
dfkaye / signal.js
Last active August 5, 2023 05:08
signal - implementation as a named event emitter vs. implementation as reactive-observable value (and value change)
// 20 July 2023
// In progress... may delete and start over... may just blog about the
// philosophical confusion that Signals have generated in the web
// development world, something easily sewn...
// Signal, an implementation that accepts a name for itself,
// and an optional `assign` method for binding the signal to
// a parent object (a feature which has little to do with the
// nature of Signals...)
@dfkaye
dfkaye / xslt-with-xhr-parse.js
Last active May 18, 2024 01:38
Using XML, XSLT, XHR, to parse and serialize HTML in the browser
// 19 June 20
// Terri passed away
// I got this to work
// XSLT in the browser
// 12 July 2023
// replaced DOMParser and "trusted" policy with async xhr parser
// see https://gist.github.com/dfkaye/a83f89d7496bb669570a1de207b5b8d4
// 13-14 July 2023