Skip to content

Commit 04b39d4

Browse files
committed
refactor(core): clean up renderer
1 parent c8b868d commit 04b39d4

File tree

8 files changed

+93
-86
lines changed

8 files changed

+93
-86
lines changed

apps/kitchen-sink-new/src/app/misc/basic/scene.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import * as THREE from 'three';
1515
template: `
1616
@if (true) {
1717
<ngt-mesh [position]="position()">
18-
<ngt-box-geometry *args="[0.5, 0.5, 0.5]" />
18+
<ngt-box-geometry *args="[0.5, 0.5, 0.5]" (attached)="onAttach($event)" />
1919
2020
<ng-content>
2121
<ngt-mesh-normal-material />
@@ -51,18 +51,11 @@ export class ConditionBox {
5151
imports: [NgtArgs],
5252
schemas: [CUSTOM_ELEMENTS_SCHEMA],
5353
changeDetection: ChangeDetectionStrategy.OnPush,
54-
host: {
55-
'(document:dblclick)': 'onDocumentDblClick($event)',
56-
},
5754
})
5855
export class Box {
5956
position = input<NgtVector3>(0);
6057
color = input('turquoise');
6158

62-
onDocumentDblClick(event: MouseEvent) {
63-
console.log('in box document dbl click', event);
64-
}
65-
6659
onAttach(event: any) {
6760
console.log('in box', event);
6861
}

libs/core/dom/src/lib/canvas.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
injectCanvasRootInitializer,
2828
injectStore,
2929
is,
30+
NGT_STORE,
3031
NgtCamera,
3132
NgtCameraParameters,
3233
NgtCanvasConfigurator,
@@ -40,7 +41,7 @@ import {
4041
NgtSize,
4142
NgtState,
4243
NgtVector3,
43-
provideStore,
44+
storeFactory,
4445
} from 'angular-three';
4546
import { NgxResize, provideResizeOptions, ResizeOptions, ResizeResult } from 'ngxtension/resize';
4647
import * as THREE from 'three';
@@ -73,7 +74,7 @@ export class NgtCanvasContent {
7374
emitInitialResult: true,
7475
debounce: { scroll: 50, resize: 0 },
7576
} as ResizeOptions),
76-
provideStore(),
77+
{ provide: NGT_STORE, useFactory: storeFactory },
7778
],
7879
host: {
7980
style: 'display: block;position: relative;width: 100%;height: 100%;overflow: hidden;',

libs/core/src/lib/portal.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { SPECIAL_INTERNAL_ADD_COMMENT_FLAG } from './renderer/constants';
2121
import { injectStore, NGT_STORE } from './store';
2222
import type { NgtComputeFunction, NgtEventManager, NgtSize, NgtState, NgtViewport } from './types';
2323
import { is } from './utils/is';
24+
import { makeId } from './utils/make';
2425
import { omit, pick } from './utils/parameters';
2526
import { signalState, SignalState } from './utils/signal-state';
2627
import { updateCamera } from './utils/update';
@@ -63,7 +64,8 @@ function mergeState(
6364
events?: NgtPortalState['events'],
6465
size?: NgtSize,
6566
) {
66-
const previousState = previousRoot.snapshot;
67+
// we never want to spread the id
68+
const { id: _, ...previousState } = previousRoot.snapshot;
6769
const state = store.snapshot;
6870

6971
let viewport: Omit<NgtViewport, 'dpr' | 'initialDpr'> | undefined = undefined;
@@ -105,7 +107,7 @@ function mergeState(
105107
{
106108
provide: NGT_STORE,
107109
useFactory: (previousStore: SignalState<NgtState>) => {
108-
const store = signalState({} as NgtState);
110+
const store = signalState({ id: makeId() } as NgtState);
109111
store.update(mergeState(previousStore, store, null!, new THREE.Vector2(), new THREE.Raycaster()));
110112
return store;
111113
},
@@ -134,7 +136,7 @@ export class NgtPortal {
134136

135137
constructor() {
136138
effect(() => {
137-
let [container, prevState] = [this.container(), this.previousStore()];
139+
let [container] = [this.container(), this.previousStore()];
138140

139141
const [size, events, restState] = [untracked(this.size), untracked(this.events), untracked(this.restState)];
140142

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
export const NGT_RENDERER_NODE_FLAG = '__ngt_renderer__';
2-
export const CANVAS_CONTENT_FLAG = '__ngt_renderer_canvas_content_flag__';
2+
export const CANVAS_CONTENT_FLAG = '__ngt_renderer_canvas_content__';
33
export const SPECIAL_INTERNAL_ADD_COMMENT_FLAG = '__ngt_renderer_add_comment__';
44
export const SPECIAL_INTERNAL_SET_PARENT_COMMENT_FLAG = '__ngt_renderer_set_parent_comment__';
55
export const NGT_MANUAL_INJECTED_STORE = '__ngt_manual_injected_store__';
6+
export const NGT_GET_NODE_ATTRIBUTE_FLAG = '__ngt_get_node_attribute__';
67

78
export const THREE_NATIVE_EVENTS = ['added', 'removed', 'childadded', 'childremoved', 'disposed'];

0 commit comments

Comments
 (0)