Skip to content

Conversation

@naramdash
Copy link

@naramdash naramdash commented Nov 5, 2025

To support Set composition methods. These methods don't make any state change.

  • difference
  • intersection
  • symmetricDifference
  • union
  • isDisjointFrom
  • isSubsetOf
  • isSupersetOf

Related issue #11398

Summary by CodeRabbit

  • New Features

    • Reactive Sets gain composition operations: difference, intersection, symmetricDifference, and union.
    • Added set relationship checks: isDisjointFrom, isSubsetOf, and isSupersetOf.
  • Tests

    • Added comprehensive tests for the new reactive Set methods, including return types, membership, and composition scenarios that verify reactive updates.

Copilot AI review requested due to automatic review settings November 5, 2025 14:08
@coderabbitai
Copy link

coderabbitai bot commented Nov 5, 2025

Walkthrough

Adds ES2024 Set composition methods (difference, intersection, symmetricDifference, union) and set-relationship predicates (isDisjointFrom, isSubsetOf, isSupersetOf) to instrumented reactive Sets and appends tests. Implementations delegate to the underlying raw Set via toRaw(); tests run only when the prototype methods exist at runtime.

Changes

Cohort / File(s) Summary
Tests
packages/reactivity/__tests__/collections/Set.spec.ts
Appends tests for difference, intersection, symmetricDifference, union, isDisjointFrom, isSubsetOf, isSupersetOf. Each test checks runtime presence of the prototype method, uses reactive vs plain Sets, asserts return types, sizes/membership, and includes // @ts-expect-error`` where applicable.
Implementation & types
packages/reactivity/src/collectionHandlers.ts
Adds type SetType = Set<any> & Target and `type SetLikeType = Pick<Set, 'size'

Sequence Diagram

sequenceDiagram
    participant App as Application
    participant Reactive as Instrumented Set
    participant Raw as Raw Set (toRaw)

    App->>Reactive: call e.g. difference(other)
    activate Reactive
    note right of Reactive `#E8F3FF`: check readonly? trigger ITERATE
    Reactive->>Raw: toRaw(this).difference(other)
    activate Raw
    Raw-->>Raw: compute result (Set / boolean)
    Raw-->>Reactive: return result
    deactivate Raw
    Reactive-->>App: return result
    deactivate Reactive

    note over Reactive,Raw `#F7FFF0`: same flow for intersection, symmetricDifference, union, isDisjointFrom, isSubsetOf, isSupersetOf
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Inspect duplicated registration points where methods are added for consistency.
  • Verify ITERATE trigger and readonly guard logic.
  • Confirm SetLikeType covers forwarded call usage and @ts-expect-error placements.

Poem

🐇 I hopped through sets both old and new,
difference, union, intersection too,
I nudged toRaw with a tiny thump,
watched reactive bits give a joyful jump,
carrots and sets — a synchronous chew! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(reactivity): support Set composition methods' clearly and specifically summarizes the main change—adding support for Set composition methods to the reactivity system.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a0581e and 70bdf36.

📒 Files selected for processing (2)
  • packages/reactivity/__tests__/collections/Set.spec.ts (1 hunks)
  • packages/reactivity/src/collectionHandlers.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/reactivity/src/collectionHandlers.ts
  • packages/reactivity/tests/collections/Set.spec.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@naramdash naramdash changed the base branch from main to minor November 5, 2025 14:16
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/reactivity/__tests__/collections/Set.spec.ts (1)

463-563: Fix “suppoort” typo in test descriptions

Several new test titles read “suppoort”. Please correct them to “support” for clarity.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f411c66 and 7953767.

📒 Files selected for processing (2)
  • packages/reactivity/__tests__/collections/Set.spec.ts (1 hunks)
  • packages/reactivity/src/collectionHandlers.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/reactivity/src/collectionHandlers.ts (2)
packages/reactivity/src/reactive.ts (2)
  • Target (18-24)
  • toRaw (378-381)
packages/shared/src/general.ts (1)
  • extend (24-24)

@naramdash naramdash changed the base branch from minor to main November 5, 2025 14:17
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/reactivity/src/collectionHandlers.ts (1)

251-251: Consider computing wrap once at the start of this extend block.

Since all four Set composition methods need the same wrapping logic, computing wrap once at line 251 (right after the extend call) would reduce duplication:

   extend(instrumentations, {
+    const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive
+
     difference(this: SetType, other: SetLikeType): SetType {

This is optional since the wrapping logic is lightweight, but it follows the pattern used elsewhere in the file (e.g., lines 116, 151).

Also applies to: 310-310

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7953767 and ad292c7.

📒 Files selected for processing (1)
  • packages/reactivity/src/collectionHandlers.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/reactivity/src/collectionHandlers.ts (3)
packages/reactivity/src/reactive.ts (2)
  • Target (18-24)
  • toRaw (378-381)
packages/shared/src/general.ts (1)
  • extend (24-24)
packages/reactivity/src/dep.ts (3)
  • track (108-165)
  • track (262-284)
  • ITERATE_KEY (242-244)
🔇 Additional comments (2)
packages/reactivity/src/collectionHandlers.ts (2)

27-28: LGTM! Type aliases are well-defined.

The type aliases appropriately represent reactive Sets and the Set-like interface required by ES2024 composition methods.


286-309: LGTM! Boolean predicates correctly track dependencies.

The boolean-returning methods (isDisjointFrom, isSubsetOf, isSupersetOf) properly track the ITERATE dependency and don't need reactive wrapping since they return primitives. The implementation correctly registers reactivity dependencies on the receiver Set.

@naramdash naramdash marked this pull request as draft November 5, 2025 15:17
@naramdash
Copy link
Author

Refactor the code, referencing #11399

@naramdash naramdash marked this pull request as ready for review November 5, 2025 16:14
@edison1105
Copy link
Member

duplicate of #11399
Thanks for the PR, but we should review #11399 if its approach is basically correct rather than create a new one.

@edison1105 edison1105 closed this Nov 6, 2025
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