Skip to content

Commit d397919

Browse files
committed
Add reactive when and bind features with automatic dependency tracking
Signal-based reactivity system for _hyperscript: - `when <expr> changes` re-runs commands when tracked dependencies change - `bind <target> to <expr>` for one-way derived bindings - `bind <target> and <target>` for two-way sync - Automatic tracking of $global, :element variables, @attributes, and .properties - MutationObserver for attribute changes, defineProperty interception for properties - Microtask batching, same-value dedup (Object.is), circular dependency guard - Auto-dispose effects when owning element is removed from DOM Includes Playwright tests for when (22 tests), bind (8 tests), and desired-behavior tests (13 tests, currently failing) documenting known footguns and areas for improvement.
1 parent 01fd042 commit d397919

14 files changed

Lines changed: 1805 additions & 15 deletions

File tree

src/_hyperscript.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {Runtime} from './core/runtime/runtime.js';
99
import {HyperscriptModule} from './core/runtime/collections.js';
1010
import {config} from './core/config.js';
1111
import {conversions} from './core/runtime/conversions.js';
12+
import {reactivity} from './core/runtime/reactivity.js';
1213

1314
// Import parse element modules
1415
import * as Expressions from './parsetree/expressions/expressions.js';
@@ -36,6 +37,8 @@ import * as WorkerFeatureModule from './parsetree/features/worker.js';
3637
import * as BehaviorFeatureModule from './parsetree/features/behavior.js';
3738
import * as InstallFeatureModule from './parsetree/features/install.js';
3839
import * as JsFeatureModule from './parsetree/features/js.js';
40+
import * as WhenFeatureModule from './parsetree/features/when.js';
41+
import * as BindFeatureModule from './parsetree/features/bind.js';
3942

4043
const globalScope = typeof self !== 'undefined' ? self : (typeof global !== 'undefined' ? global : this);
4144

@@ -76,6 +79,8 @@ kernel.registerModule(WorkerFeatureModule);
7679
kernel.registerModule(BehaviorFeatureModule);
7780
kernel.registerModule(InstallFeatureModule);
7881
kernel.registerModule(JsFeatureModule);
82+
kernel.registerModule(WhenFeatureModule);
83+
kernel.registerModule(BindFeatureModule);
7984

8085
// ===== Public API =====
8186

@@ -111,7 +116,7 @@ const _hyperscript = Object.assign(
111116
},
112117

113118
internals: {
114-
tokenizer, runtime,
119+
tokenizer, runtime, reactivity,
115120
createParser: (tokens) => new Parser(kernel, tokens),
116121
},
117122

0 commit comments

Comments
 (0)