From f8bd93253c1b4c23d7c58fa89824ed818611f88f Mon Sep 17 00:00:00 2001 From: Zhong Date: Mon, 23 Jun 2025 09:01:33 +0800 Subject: [PATCH 1/7] refactor(computedInject): rename ctx param to oldValue (#4829) --- packages/core/computedInject/index.test.ts | 20 ++++++++++++++++++++ packages/core/computedInject/index.ts | 8 ++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/core/computedInject/index.test.ts b/packages/core/computedInject/index.test.ts index a501ec974b9..ed2a100c152 100644 --- a/packages/core/computedInject/index.test.ts +++ b/packages/core/computedInject/index.test.ts @@ -23,4 +23,24 @@ describe('computedInject', () => { expect(anotherComputedNum.value).toBe(11) }) }) + + it('should pass oldValue to computed getter', () => { + useInjectedSetup(() => { + const curValue = shallowRef(0) + const oldValue = shallowRef() + + const computedNum = computedInject(Key, (source, previous) => { + oldValue.value = previous + return curValue.value + (source?.value ?? 0) + }) + + expect(computedNum.value).toBe(1) + expect(oldValue.value).toBeUndefined() + + curValue.value = 1 + + expect(computedNum.value).toBe(2) + expect(oldValue.value).toBe(1) + }) + }) }) diff --git a/packages/core/computedInject/index.ts b/packages/core/computedInject/index.ts index 552ee1f1615..4ac108cab09 100644 --- a/packages/core/computedInject/index.ts +++ b/packages/core/computedInject/index.ts @@ -1,8 +1,8 @@ import type { ComputedRef, InjectionKey } from 'vue' import { computed, inject } from 'vue' -export type ComputedInjectGetter = (source: T | undefined, ctx?: any) => K -export type ComputedInjectGetterWithDefault = (source: T, ctx?: any) => K +export type ComputedInjectGetter = (source: T | undefined, oldValue?: K) => K +export type ComputedInjectGetterWithDefault = (source: T, oldValue?: K) => K export type ComputedInjectSetter = (v: T) => void export interface WritableComputedInjectOptions { @@ -48,11 +48,11 @@ export function computedInject( source = inject(key, defaultSource, treatDefaultAsFactory) as T if (typeof options === 'function') { - return computed(ctx => options(source, ctx)) + return computed(oldValue => options(source, oldValue as K | undefined)) } else { return computed({ - get: ctx => options.get(source, ctx), + get: oldValue => options.get(source, oldValue as K | undefined), set: options.set, }) } From 335f74fefe6c8266929b50ceacf4558af385b611 Mon Sep 17 00:00:00 2001 From: Zhong Date: Mon, 23 Jun 2025 14:52:59 +0800 Subject: [PATCH 2/7] test: render Comp to trigger its setup (#4830) --- packages/.test/mount.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/.test/mount.ts b/packages/.test/mount.ts index a4fd0e1b455..d15da2ae594 100644 --- a/packages/.test/mount.ts +++ b/packages/.test/mount.ts @@ -41,7 +41,7 @@ export function useInjectedSetup(setup: () => V) { provide(Key, shallowRef(1)) }, render() { - return h('div', []) + return h(Comp) }, }) From 4d125f241027cb9e8bcd83d1e6e2096f3774f1fd Mon Sep 17 00:00:00 2001 From: Melkumyants Danila <90843433+whiteyebrw@users.noreply.github.com> Date: Sat, 28 Jun 2025 13:08:39 +0300 Subject: [PATCH 3/7] feat(useSpeechSynthesis): add reactivity for volume (#4837) --- packages/core/useSpeechSynthesis/demo.vue | 10 ++++++++++ packages/core/useSpeechSynthesis/index.ts | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/core/useSpeechSynthesis/demo.vue b/packages/core/useSpeechSynthesis/demo.vue index 19caef00c38..af1338785dd 100644 --- a/packages/core/useSpeechSynthesis/demo.vue +++ b/packages/core/useSpeechSynthesis/demo.vue @@ -6,11 +6,13 @@ const voice = deepRef(undefined as unknown as SpeechSynthe const text = shallowRef('Hello, everyone! Good morning!') const pitch = shallowRef(1) const rate = shallowRef(1) +const volume = shallowRef(1) const speech = useSpeechSynthesis(text, { voice, pitch, rate, + volume, }) let synth: SpeechSynthesis @@ -96,6 +98,14 @@ function stop() { +
+
+ +
+ +
+
+