feat: add onChange API for collection state with useCollectionURLState#292
Draft
IzumiSy wants to merge 7 commits into
Draft
feat: add onChange API for collection state with useCollectionURLState#292IzumiSy wants to merge 7 commits into
IzumiSy wants to merge 7 commits into
Conversation
commit: |
…izer Introduce a pluggable synchronizer interface for persisting collection state (filters, sort, pageSize) to external stores. - Add CollectionSnapshot and CollectionStateSynchronizer types - Add synchronizer option to UseCollectionOptions / useCollectionVariables - Implement useSearchParamsSynchronizer (URL search params persistence) with prefix and debounce support - Add tests for synchronizer integration and useSearchParamsSynchronizer
…le synchronizer - Add collectionReducer with source tracking (init/user/sync) to eliminate ref flags - Extract useSynchronizerBridge hook for subscribe/write-back logic - Refactor useCollectionVariables to use useReducer + bridge - Refactor useCursorPagination to accept external pageSize parameter - Update useSearchParamsSynchronizer to use subscribe/write pattern - Update tests for new architecture
- CollectionStateSynchronizer → CollectionStatePersistence - useSearchParamsSynchronizer → useSearchParamsPersistence - Simplify to read()/write() pattern (no subscribe) - Inline use-collection-state into use-collection-variables - Remove react-router dependency from persistence layer
Restore original useState pattern for filters/sort/pageSize to minimize diff from main. Persistence read/write is the only addition.
- rename useSearchParamsPersistence to useCollectionURLPersistence - rename hook files to use-collection-url-persistence - update exports, tests, and nextjs example usage - keep API unreleased so no deprecation alias
032133b to
4093ece
Compare
- remove unnecessary setPageSize wrapper in use-collection-variables - restore cursor pagination tests removed by unrelated changes
- Remove CollectionStatePersistence interface - Add onChange callback to UseCollectionOptions - Make CollectionSnapshot fields required - Rename useCollectionURLPersistence to useCollectionURLState - useCollectionURLState returns read/write accessor (read() for params, write for onChange) - Merge persistence tests into use-collection-variables.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add an
onChangecallback touseCollectionVariablesthat notifies on every user-initiated state change (filters, sort, pageSize). Includes a built-inuseCollectionURLStatehook that provides a read/write accessor for URL-based state.Design
Instead of a
persistenceinterface that the hook calls internally, the API follows standard React conventions:params— synchronous initial state (no delayed hydration)onChange— explicit notification on state changes (unidirectional data flow)Helper hooks like
useCollectionURLStatereturn a{ read, write }accessor that wires directly intoparamsandonChange:API
useCollectionVariablesoptionsuseCollectionURLStateURL format:
p=20s=name:ascf.field:operator=value(repeated params for multi-value filters)