Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2554a59

Browse files
committed
feat(core): configurable max notification skip count
1 parent 154e9b9 commit 2554a59

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

libs/core/src/lib/instance.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,10 @@ function notifyAncestors(instance: NgtInstanceNode | null, type: 'objects' | 'no
228228
const id = instance.__ngt_id__ || instance['uuid'];
229229
if (!id) return;
230230

231+
const maxNotificationSkipCount = localState.store?.snapshot.maxNotificationSkipCount || 5;
231232
const cached = notificationCache.get(id);
232233

233-
if (!cached || cached.lastType !== type || cached.skipCount > 5) {
234+
if (!cached || cached.lastType !== type || cached.skipCount > maxNotificationSkipCount) {
234235
notificationCache.set(id, { skipCount: 0, lastType: type });
235236

236237
if (notificationCache.size === 1) {

libs/core/src/lib/renderer/renderer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ import { attachThreeNodes, internalDestroyNode, kebabToPascal, NgtRendererClassI
4141

4242
export interface NgtRendererFactory2Options {
4343
verbose?: boolean;
44+
/**
45+
* When a change happens to an object's direct children, Angular Three will notify the object's ancestors
46+
* of this change so the ancestors are aware of the updated matrices of the object. In order to reduce the
47+
* number of notifications, Angular Three caches and skips notifications when possible.
48+
*
49+
* However, this can cause missed notifications in some cases. Control the number of skips with this option.
50+
*
51+
* @default 5
52+
*/
53+
maxNotificationSkipCount?: number;
4454
}
4555

4656
export const NGT_RENDERER_OPTIONS = new InjectionToken<NgtRendererFactory2Options>('NGT_RENDERER_OPTIONS');

libs/core/src/lib/store.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ElementRef, InjectOptions, InjectionToken, effect, inject } from '@angu
33
import { Subject } from 'rxjs';
44
import * as THREE from 'three';
55
import { injectLoop } from './loop';
6+
import { NGT_RENDERER_OPTIONS } from './renderer/renderer';
67
import type {
78
NgtBeforeRenderRecord,
89
NgtCamera,
@@ -20,6 +21,7 @@ import { updateCamera } from './utils/update';
2021

2122
export function storeFactory() {
2223
const { invalidate, advance } = injectLoop();
24+
const rendererOptions = inject(NGT_RENDERER_OPTIONS, { optional: true }) || {};
2325
const document = inject(DOCUMENT);
2426
const window = document.defaultView || undefined;
2527

@@ -47,6 +49,7 @@ export function storeFactory() {
4749

4850
const store: SignalState<NgtState> = signalState<NgtState>({
4951
id: makeId(),
52+
maxNotificationSkipCount: rendererOptions.maxNotificationSkipCount || 5,
5053
pointerMissed$: pointerMissed$.asObservable(),
5154
events: { priority: 1, enabled: true, connected: false },
5255

libs/core/src/lib/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ export interface NgtState {
359359
previousRoot: SignalState<NgtState> | null;
360360
/** Internals */
361361
internal: NgtInternalState;
362+
/** maxSkipCount from renderer options */
363+
maxNotificationSkipCount?: number;
362364
}
363365

364366
export interface NgtCanvasOptions {

0 commit comments

Comments
 (0)