Improve UI performance by optimizing reactivity
- Replace `ref`s with `shallowRef` when deep reactivity is not needed. - Replace `readonly`s with `shallowReadonly` where the goal is to only prevent `.value` mutation. - Remove redundant `ref` in `SizeObserver.vue`. - Remove redundant nested `ref` in `TooltipWrapper.vue`. - Remove redundant `events` export from `UseCollectionState.ts`. - Remove redundant `computed` from `UseCollectionState.ts`. - Remove `timestamp` from `TreeViewFilterEvent` that becomes unnecessary after using `shallowRef`. - Add missing unit tests for `UseTreeViewFilterEvent`. - Add missing stub for `FilterChangeDetails`.
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
ref, computed, readonly,
|
||||
} from 'vue';
|
||||
import { shallowRef, shallowReadonly } from 'vue';
|
||||
import { IApplicationContext, IReadOnlyApplicationContext } from '@/application/Context/IApplicationContext';
|
||||
import { ICategoryCollectionState, IReadOnlyCategoryCollectionState } from '@/application/Context/State/ICategoryCollectionState';
|
||||
import { IEventSubscriptionCollection } from '@/infrastructure/Events/IEventSubscriptionCollection';
|
||||
@@ -16,7 +14,7 @@ export function useCollectionState(
|
||||
throw new Error('missing events');
|
||||
}
|
||||
|
||||
const currentState = ref<ICategoryCollectionState>(context.state);
|
||||
const currentState = shallowRef<IReadOnlyCategoryCollectionState>(context.state);
|
||||
events.register([
|
||||
context.contextChanged.on((event) => {
|
||||
currentState.value = event.newState;
|
||||
@@ -66,8 +64,7 @@ export function useCollectionState(
|
||||
modifyCurrentContext,
|
||||
onStateChange,
|
||||
currentContext: context as IReadOnlyApplicationContext,
|
||||
currentState: readonly(computed<IReadOnlyCategoryCollectionState>(() => currentState.value)),
|
||||
events: events as IEventSubscriptionCollection,
|
||||
currentState: shallowReadonly(currentState),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user