feat: add createExternalStore utility and ClockProvider#195
Conversation
Add a generic external store factory (createExternalStore) using useSyncExternalStore that allows components to subscribe to frequently-updating data sources without causing unnecessary re-renders. Includes a pre-built clock store (ClockProvider, useClock, useClockSelector) that wraps the existing Clock component, enabling projects to move clock state out of Redux and eliminate per-second re-renders of all connected components.
8f3375c to
cd28bef
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a createExternalStore factory (Provider, useValue, useSelector) with React 16/17 shim, a ClockProvider wiring Clock into that store, tests for both modules, barrel exports, webpack entries, and README/dependency updates describing the shim and migration to React 18+. ChangesExternal Store and Clock Context Implementation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/components/__tests__/clock-context.test.js`:
- Around line 58-62: Two tests directly reassign console.error around rendering
ClockReader which can leak mocks if an exception occurs; replace those direct
assignments with jest.spyOn(console, 'error').mockImplementation(...) and ensure
you call mockRestore() in a finally block so the spy is always restored,
updating both the block that wraps render(<ClockReader />) (previously lines
58-62) and the similar block around lines 80-84; reference the ClockReader
render and use mockRestore() to guarantee cleanup.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 322fb309-5b6c-4966-b31b-9e06d7494ddd
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (8)
package.jsonreadme.mdsrc/components/__tests__/clock-context.test.jssrc/components/clock-context.jssrc/components/index.jssrc/utils/__tests__/external-store.test.jssrc/utils/external-store.jswebpack.common.js
Add a generic external store factory (
createExternalStore) usinguseSyncExternalStorethat lets components subscribe to frequently-updating data sources without unnecessary re-renders.Includes a pre-built clock store (
ClockProvider,useClock,useClockSelector) wrapping the existing Clock component. This enables projects to move clock state out of Redux, eliminating per-second re-renders of all connected components.API
createExternalStore(name)→{ Provider, useValue, useSelector }useValue()— re-renders on every emituseSelector(compute, isEqual)— re-renders only when the computed result changesClock usage
ref: https://app.clickup.com/t/86b8dm4da
Summary by CodeRabbit
New Features
Documentation
Tests