1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 02:44:45 +00:00

fix(packages/vue): revert to old version useRenderCount

This commit is contained in:
2025-05-09 13:09:03 +07:00
parent a07ac35db9
commit 3a2837c1a1
2 changed files with 5 additions and 17 deletions

View File

@@ -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);
});
});

View File

@@ -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);
}