feat(store): return callback result from batch and add subscriber test coverage #395
main fromrefs/pull/395/head·opened 🎯 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:
- Return values are correctly passed through atch.
- 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
batchnow 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
batchreturns the callback’s value.
- Added coverage confirming that subscribers are notified once after batched updates, with the final state, and that
- 1
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 924f7ff68696b69c716f733fdede8ae479053791 and e4821f34cdd267b152b2751128dd7c4dcab3cb11.
You can disable this status message by setting the
reviews.review_statustofalsein 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 51ddb30396dd01d10dcab50a0a3a5f4d7afb72d3 and 924f7ff68696b69c716f733fdede8ae479053791.
📒 Files selected for processing (2)
-
packages/store/src/atom.tspackages/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#
batchnow 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.tsbatchreturns 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
924f7The 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 |
3 | 2-
❌ Failed checks (2 warnings)#
Check name Status Explanation Resolution Description check 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.tschanges 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 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 The title clearly and concisely describes both primary changes: returning the callback result from batchand adding subscriber test coverage.Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check 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.tschanges the publicbatchAPI 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.
Comment `@coderabbitai help` to get the list of available commands.-
TkDodo closed this
Sign in to join this conversation.
⚠️ No Changeset found#
Latest commit: e4821f34cdd267b152b2751128dd7c4dcab3cb11
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