mirror of
https://github.com/robonen/tools.git
synced 2026-03-20 10:54:44 +00:00
fix(packages/vue): revert to old version useRenderCount
This commit is contained in:
@@ -32,7 +32,7 @@ describe('useRenderCount', () => {
|
|||||||
await nextTick();
|
await nextTick();
|
||||||
|
|
||||||
// Will trigger a render
|
// Will trigger a render
|
||||||
expect(component.vm.count).toBe(1);
|
expect(component.vm.count).toBe(2);
|
||||||
expect(component.text()).toBe('1');
|
expect(component.text()).toBe('1');
|
||||||
|
|
||||||
component.vm.visibleCount++;
|
component.vm.visibleCount++;
|
||||||
@@ -40,7 +40,7 @@ describe('useRenderCount', () => {
|
|||||||
await nextTick();
|
await nextTick();
|
||||||
|
|
||||||
// Will trigger a single render for both updates
|
// 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');
|
expect(component.text()).toBe('3');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -70,6 +70,6 @@ describe('useRenderCount', () => {
|
|||||||
await nextTick();
|
await nextTick();
|
||||||
|
|
||||||
// Will trigger a single render for both updates
|
// 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 { onMounted, onUpdated, readonly, type ComponentInternalInstance } from 'vue';
|
||||||
import { useCounter } from '../useCounter';
|
import { useCounter } from '../useCounter';
|
||||||
import { getLifeCycleTarger } from '../..';
|
import { getLifeCycleTarger } from '../..';
|
||||||
import { SyncMutex } from '@robonen/stdlib';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name useRenderCount
|
* @name useRenderCount
|
||||||
@@ -20,22 +19,11 @@ import { SyncMutex } from '@robonen/stdlib';
|
|||||||
* @since 0.0.1
|
* @since 0.0.1
|
||||||
*/
|
*/
|
||||||
export function useRenderCount(instance?: ComponentInternalInstance) {
|
export function useRenderCount(instance?: ComponentInternalInstance) {
|
||||||
const mutex = new SyncMutex();
|
|
||||||
const { count, increment } = useCounter(0);
|
const { count, increment } = useCounter(0);
|
||||||
const target = getLifeCycleTarger(instance);
|
const target = getLifeCycleTarger(instance);
|
||||||
|
|
||||||
const incrementEffect = () => {
|
onMounted(increment, target);
|
||||||
if (mutex.isLocked) {
|
onUpdated(increment, target);
|
||||||
mutex.unlock();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mutex.lock();
|
|
||||||
increment();
|
|
||||||
};
|
|
||||||
|
|
||||||
onMounted(incrementEffect, target);
|
|
||||||
onUpdated(incrementEffect, target);
|
|
||||||
|
|
||||||
return readonly(count);
|
return readonly(count);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user