Skip to content

feat: Reactivity System Improvements & Test Coverage#64

Merged
treardon17 merged 22 commits into
mainfrom
chore/tdr/improvements
Dec 18, 2025
Merged

feat: Reactivity System Improvements & Test Coverage#64
treardon17 merged 22 commits into
mainfrom
chore/tdr/improvements

Conversation

@treardon17
Copy link
Copy Markdown
Collaborator

Claude

This PR adds a CLAUDE.md file, and claude helped find and fix some defects, performance issues, and added map/set support.

Bug Fixes

Scheduler Error Recovery

Problem: If a scheduled task threw an error, the scheduler's SCHEDULER_ID was never reset, preventing all future tasks from being scheduled.

Solution: Added proper error handling with try/catch around individual tasks and a finally block to always reset the scheduler state:


Code Improvements

Consolidated Type Detection

  • Simplified Reactive.getStringType() to a clean implementation using isPlainObject():
  • The isPlainObject check only proxies objects created via {} or Object.create(null). This naturally excludes problematic types (Promise, Date, WeakMap, WeakSet, RegExp, Error, ArrayBuffer, typed arrays, DOM nodes, class instances) because none of them have Object.prototype as their direct prototype.
  • Updated JSDoc Import Paths
  • Changed all documentation examples from 'madrone' to '@madronejs/core' to match the new package name.

Test Coverage Added

New Test Files

File Tests Coverage
src/spec/util.spec.ts 11 applyClassMixins, getDefaultDescriptors
src/spec/global.spec.ts 30 Integration registry, toRaw, objectAccessed, lastAccessed

Extended Existing Tests

observer.spec.ts

  • cache: false mode (recomputes every access)
  • onGet hook (called on every value access)
  • onImmediateChange hook (synchronous change notification)
  • Writable computed with onSet hook
  • Error cases for missing setters

reactive.spec.ts

  • onDelete callback for property deletion
  • onHas callback for in operator and Object.keys()
  • Custom needsProxy function
  • Symbol keys
  • Frozen/sealed objects (non-configurable properties)
  • Shallow reactivity (deep: false)
  • Edge cases: null prototype objects, getters/setters, circular references

scheduler.spec.ts

  • Error handling: continues processing after task throws
  • Recovery: allows new tasks after errors
  • Nested task error handling
  • Multiple errors in same batch

Total: 295 tests (all passing)


Performance Implications

  1. Reduced Proxy Overhead: By not proxying class instances and native objects, there's less memory overhead and fewer proxy trap invocations for objects that don't need reactivity.
  2. Simplified Type Detection: The consolidated isPlainObject check is a single prototype comparison instead of multiple instanceof checks, reducing the cost of type detection.
  3. Robust Scheduler: Error handling prevents the scheduler from getting stuck, ensuring reactive updates continue even when individual handlers fail.

@treardon17 treardon17 requested a review from bitencode December 18, 2025 00:02
@treardon17 treardon17 self-assigned this Dec 18, 2025
Copy link
Copy Markdown
Collaborator

@bitencode bitencode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me - I looked at code changes and briefly scanned tests and doc changes. Don't have a good way to test this other then unit tests, so I'm assuming (a bit) that it's good. 😉
Give my regards and thanks to Claude for help with JSDoc, examples and unit tests 😂
Thank you - it does look safer and possibly more performant 👍

@treardon17 treardon17 merged commit c0c60e0 into main Dec 18, 2025
5 checks passed
@treardon17 treardon17 deleted the chore/tdr/improvements branch December 18, 2025 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants