Skip to content

feat(store): return callback result from batch and add subscriber test coverage - #395

Closed
grzdev wants to merge 2 commits into
TanStack:mainfrom
grzdev:test/store-batch-subscriber-notifications
Closed

grzdev wants to merge 2 commits into
TanStack:mainfrom
grzdev:test/store-batch-subscriber-notifications

Conversation

@grzdev

@grzdev grzdev commented Oct 11, 2026 •

Copy link
Copy Markdown

🎯 Changes

  • Updates �atch(fn: () => T): T in @tanstack/store (packages/store/src/atom.ts) so it returns the value produced by the batched function execution.
  • Adds comprehensive test coverage in �atch.test.ts verifying that:
    1. Return values are correctly passed through �atch.
    2. Store subscribers are notified exactly once with the final value after the entire batch finishes rather than on intermediate state transitions.

✅ Checklist

  • I have read the contributing guide
  • Tests pass locally (pnpm --filter @tanstack/store run test:lib)
  • ESLint passes locally (pnpm --filter @tanstack/store run test:eslint)
  • TypeScript type checks pass locally (pnpm --filter @tanstack/store run test:types)

🚀 Release Impact

  • Published package changes (requires changeset)
  • Tests / CI / Dev only

Summary by CodeRabbit

  • New Features

    • batch now returns the value produced by its callback.
  • Tests

    • Added coverage confirming that subscribers are notified once after batched updates, with the final state, and that batch returns the callback’s value.

@changeset-bot

changeset-bot Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e4821f3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository: TanStack/store/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aa4afdf7-c6df-4c37-83de-76f578f22ec7
📥 Commits

Reviewing files that changed from the base of the PR and between 924f7ff and e4821f3.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: TanStack/store/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7c0a01ba-a5d7-47be-b982-33c058fba0ea
📥 Commits

Reviewing files that changed from the base of the PR and between 51ddb30 and 924f7ff.

📒 Files selected for processing (2)
  • packages/store/src/atom.ts
  • packages/store/tests/batch.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

📝 Walkthrough

Walkthrough

batch now returns the value produced by its callback. Tests check that multiple updates in a batch notify subscribers once after completion, with the final state.

Changes

Batch behavior

Layer / File(s) Summary
Batch return and flush behavior
packages/store/src/atom.ts, packages/store/tests/batch.test.ts
batch returns its callback’s value and retains its existing flush behavior. Tests check one subscriber notification after three updates and verify the returned value.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Suggested reviewers: sheraff

Merge Risk: ⚪ Minimal · up to 924f7

The change exposes the batch callback’s result without altering flush behavior, and the added tests check the final subscriber notification. No actionable merge-blocking risk is evident in the reviewed changes.

Pre-merge checks | Passed 3 | Failed 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check Warning The description includes all required sections and explains the implementation and tests. However, it marks the change as tests/CI/dev-only even though packages/store/src/atom.ts changes the public … Correct the Release Impact section. Mark the change as affecting published code and add the required changeset, or provide repository-specific evidence that this package change is not released.
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes both primary changes: returning the callback result from batch and adding subscriber test coverage.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description includes all required sections and explains the implementation and tests. However, it marks the change as tests/CI/dev-only even though packages/store/src/atom.ts changes the public batch API and may affect published code.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@TkDodo TkDodo closed this Oct 17, 2026
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