Skip to content

Conversation

Copy link

Copilot AI commented Nov 10, 2025

Introduces a layered hooks architecture for callback management in DataCore, replacing direct callback storage with inherited hooks infrastructure. Callbacks now return void instead of transforming values.

Architecture Changes

New inheritance hierarchy:

Immutability → HooksCore → HooksBase<T> → DataCore<T>
  • HooksCore: Core lifecycle hook (onDestroy)
  • HooksBase: Property-specific hooks (onChange, onSet) with typed parameters
  • DataCore: Removed 3 private callback fields and their accessors, now inherited from HooksBase

Callback Signature Changes

Callbacks are now notification-only (void return):

// Before
onChange: (value: T, oldValue: T) => T
onSet: (value: T) => T

// After  
onChange: (value: T, oldValue: T) => void
onSet: (value: T) => void

Implementation Updates

DataBase.set() and WeakData.set() adapted to invoke callbacks without expecting transformed values:

// Invoke onSet before setting
if (typeof super.onSetCallback === 'function') {
  super.onSetCallback(value);
}
this.#value = value;

// Invoke onChange after setting if value changed
if (typeof this.onChangeCallback === 'function' && hasChanged(oldValue, value)) {
  this.onChangeCallback(value, oldValue);
}

Exports

Added HooksCore and HooksBase to public API.

Testing

Comprehensive test suite covers:

  • Hook invocation timing and parameters
  • Callback registration/unregistration
  • Multiple hooks interaction
  • Void return type compliance
Original prompt

Refactor the DataCore class to integrate a new hooks system using HooksBase and HooksCore for enhanced callback management, including support for property-specific change and set hooks. Update the inheritance hierarchy to extend HooksBase (which extends HooksCore extending Immutability) instead of directly extending Immutability, and adjust callback types to return void for consistency. Remove redundant callback storage from DataCore and leverage the inherited hooks from HooksBase.

This pull request was created as a result of the following prompt from Copilot chat.

Refactor the DataCore class to integrate a new hooks system using HooksBase and HooksCore for enhanced callback management, including support for property-specific change and set hooks. Update the inheritance hierarchy to extend HooksBase (which extends HooksCore extending Immutability) instead of directly extending Immutability, and adjust callback types to return void for consistency. Remove redundant callback storage from DataCore and leverage the inherited hooks from HooksBase.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 10, 2025 14:31
…s system

Co-authored-by: sciborrudnicki <19817956+sciborrudnicki@users.noreply.github.com>
Co-authored-by: sciborrudnicki <19817956+sciborrudnicki@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor DataCore class to integrate new hooks system Refactor DataCore to use hooks system via HooksBase and HooksCore Nov 10, 2025
Copilot AI requested a review from sciborrudnicki November 10, 2025 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants