Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat(UseRefHistoryOptions): add shouldCommit #4471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
Loading
from
Prev Previous commit
Next Next commit
refactor: rename beforeCommit to shouldCommit
  • Loading branch information
JonathanSchndr committed Jan 10, 2025
commit ca3bff7b0613b9ce40855f3fbd40e5a24ae5da52
8 changes: 4 additions & 4 deletions 8 packages/core/useRefHistory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface UseRefHistoryOptions<Raw, Serialized = Raw> extends Configurabl
* @param newValue New value
* @returns boolean indicating if commit should proceed
*/
beforeCommit?: (oldValue: Serialized | undefined, newValue: Raw) => boolean
shouldCommit?: (oldValue: Serialized | undefined, newValue: Raw) => boolean
JonathanSchndr marked this conversation as resolved.
Show resolved Hide resolved
}

export interface UseRefHistoryReturn<Raw, Serialized> extends UseManualRefHistoryReturn<Raw, Serialized> {
Expand Down Expand Up @@ -100,7 +100,7 @@ export function useRefHistory<Raw, Serialized = Raw>(
deep = false,
flush = 'pre',
eventFilter,
beforeCommit,
shouldCommit,
} = options

const {
Expand Down Expand Up @@ -146,10 +146,10 @@ export function useRefHistory<Raw, Serialized = Raw>(
// so we do not trigger an extra commit in the async watcher
ignorePrevAsyncUpdates()

if (beforeCommit) {
if (shouldCommit) {
const history = manualHistory.history.value
const lastValue = history.length > 0 ? history[history.length - 1].snapshot : undefined
if (!beforeCommit(lastValue, source.value))
if (!shouldCommit(lastValue, source.value))
return
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.