From 9cb71af85b2874447135bca87562c46df1b83edc Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Wed, 8 Oct 2025 14:41:45 +0800 Subject: [PATCH] feat: get old value of preference when is was updated --- client/ui/preference/PreferenceStore.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/ui/preference/PreferenceStore.ts b/client/ui/preference/PreferenceStore.ts index f4e14b5..b8353a0 100644 --- a/client/ui/preference/PreferenceStore.ts +++ b/client/ui/preference/PreferenceStore.ts @@ -1,7 +1,7 @@ import React from 'react' export default class PreferenceStore { - declare onUpdate: (value: T) => void + declare onUpdate: (value: T, oldvalue: T) => void declare state: T declare setState: React.Dispatch> constructor() { @@ -12,15 +12,16 @@ export default class PreferenceStore { createUpdater() { return (key: string, value: unknown) => { + const oldvalue = this.state const newValue = { ...this.state, [key]: value, } this.setState(newValue) - this.onUpdate?.(newValue) + this.onUpdate?.(newValue, oldvalue) } } - setOnUpdate(onUpdate: (value: T) => void) { + setOnUpdate(onUpdate: (value: T, oldvalue: T) => void) { this.onUpdate = onUpdate } }