Commit 0be8a11
committed
Implement reactive data binding mechanism for ldview
This commit introduces a reactive data binding system that enables automatic DOM updates when data changes, similar to modern frameworks like Vue.js.
## Core Changes
### 1. New ldreactive Library (src/ldreactive.ls)
- Independent reactive data binding library
- Uses ES6 Proxy for dependency tracking
- Supports deep object/array tracking
- Event-driven architecture (on/fire pattern)
- Batch update support
- Property exclusion mechanism
Features:
- `get()` - Get reactive proxy
- `raw()` - Get raw data without tracking
- `set(data)` - Set/update data
- `track(name, fn)` - Track dependencies
- `untrack(name)` - Stop tracking
- `watch(key, callback)` - Watch specific properties
- `batch(fn)` - Batch multiple updates
### 2. ldview Integration (src/ldview.ls)
- Seamless integration with ldreactive
- Auto-detect reactive context
- Automatic handler re-rendering on data changes
- Per-handler reactive control via `reactive: false`
- Support for all handler types (handler, text, attr, style)
Usage:
```javascript
const state = new ldview.reactive({ count: 0 });
new ldview({
root: '#app',
ctx: state,
handler: {
counter: ({node, ctx}) => node.textContent = ctx.count
}
});
state.get().count++; // Auto re-renders counter handler
```
### 3. Build System Updates
- Updated build script to compile ldreactive
- Generate both regular and minified versions
- Copy to web assets directory
### 4. Documentation & Tests
- REACTIVE.md - Comprehensive documentation with examples
- test-ldreactive.js/html - Standalone ldreactive tests (13 tests)
- test-integration.js/html - Integration tests (10 tests)
- All tests passing ✓
## Technical Details
- Deep property tracking (e.g., `user.profile.name`)
- Array mutation tracking (push, pop, splice, etc.)
- WeakMap-based proxy caching for performance
- Event system for change notifications
- No breaking changes to existing ldview API
- Backward compatible (reactive is opt-in)
## Browser Support
Requires ES6 Proxy support:
- Chrome 49+, Firefox 18+, Safari 10+, Edge 12+
- Not compatible with IE11
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent 5a5b374 commit 0be8a11
File tree
16 files changed
+2352
-33
lines changed- dist
- src
- web/static/assets/lib/ldview/dev
16 files changed
+2352
-33
lines changedLarge diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
4 | 8 | | |
5 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
6 | 14 | | |
7 | 15 | | |
| 16 | + | |
8 | 17 | | |
9 | 18 | | |
| 19 | + | |
10 | 20 | | |
11 | 21 | | |
12 | 22 | | |
13 | 23 | | |
| 24 | + | |
14 | 25 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| |||
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
23 | 37 | | |
24 | 38 | | |
25 | 39 | | |
| |||
368 | 382 | | |
369 | 383 | | |
370 | 384 | | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
379 | 395 | | |
380 | 396 | | |
381 | 397 | | |
382 | 398 | | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
383 | 403 | | |
384 | 404 | | |
385 | 405 | | |
| |||
424 | 444 | | |
425 | 445 | | |
426 | 446 | | |
427 | | - | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
428 | 454 | | |
429 | 455 | | |
430 | | - | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
431 | 462 | | |
432 | 463 | | |
433 | | - | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
434 | 470 | | |
435 | 471 | | |
436 | 472 | | |
437 | 473 | | |
438 | 474 | | |
439 | | - | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
440 | 481 | | |
441 | 482 | | |
442 | 483 | | |
| |||
614 | 655 | | |
615 | 656 | | |
616 | 657 | | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
617 | 661 | | |
618 | 662 | | |
619 | 663 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments