From 3a2837c1a1b4f6dbdc0f8fb2286b8130c6c8a2d0 Mon Sep 17 00:00:00 2001 From: robonen Date: Fri, 9 May 2025 13:09:03 +0700 Subject: [PATCH] fix(packages/vue): revert to old version useRenderCount --- .../src/composables/useRenderCount/index.test.ts | 6 +++--- .../vue/src/composables/useRenderCount/index.ts | 16 ++-------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/packages/vue/src/composables/useRenderCount/index.test.ts b/packages/vue/src/composables/useRenderCount/index.test.ts index 93b8ace..8fe517f 100644 --- a/packages/vue/src/composables/useRenderCount/index.test.ts +++ b/packages/vue/src/composables/useRenderCount/index.test.ts @@ -32,7 +32,7 @@ describe('useRenderCount', () => { await nextTick(); // Will trigger a render - expect(component.vm.count).toBe(1); + expect(component.vm.count).toBe(2); expect(component.text()).toBe('1'); component.vm.visibleCount++; @@ -40,7 +40,7 @@ describe('useRenderCount', () => { await nextTick(); // Will trigger a single render for both updates - expect(component.vm.count).toBe(2); + expect(component.vm.count).toBe(3); expect(component.text()).toBe('3'); }); @@ -70,6 +70,6 @@ describe('useRenderCount', () => { await nextTick(); // Will trigger a single render for both updates - expect(count.value).toBe(1); + expect(count.value).toBe(2); }); }); \ No newline at end of file diff --git a/packages/vue/src/composables/useRenderCount/index.ts b/packages/vue/src/composables/useRenderCount/index.ts index 1037271..d40737b 100644 --- a/packages/vue/src/composables/useRenderCount/index.ts +++ b/packages/vue/src/composables/useRenderCount/index.ts @@ -1,7 +1,6 @@ import { onMounted, onUpdated, readonly, type ComponentInternalInstance } from 'vue'; import { useCounter } from '../useCounter'; import { getLifeCycleTarger } from '../..'; -import { SyncMutex } from '@robonen/stdlib'; /** * @name useRenderCount @@ -20,22 +19,11 @@ import { SyncMutex } from '@robonen/stdlib'; * @since 0.0.1 */ export function useRenderCount(instance?: ComponentInternalInstance) { - const mutex = new SyncMutex(); const { count, increment } = useCounter(0); const target = getLifeCycleTarger(instance); - const incrementEffect = () => { - if (mutex.isLocked) { - mutex.unlock(); - return; - } - - mutex.lock(); - increment(); - }; - - onMounted(incrementEffect, target); - onUpdated(incrementEffect, target); + onMounted(increment, target); + onUpdated(increment, target); return readonly(count); } \ No newline at end of file