mirror of
https://github.com/robonen/tools.git
synced 2026-03-20 19:04:46 +00:00
fix(packages/vue): revert to old version useRenderCount
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user