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

Skip to content

Commit 800bc6d

Browse files
committed
refactor(core): use DOM_PARENT constant for __ngt_dom_parent__
1 parent 9fa18f5 commit 800bc6d

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

libs/core/src/lib/html.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Type,
1111
} from '@angular/core';
1212
import { HTML } from './renderer';
13+
import { DOM_PARENT } from './renderer/constants';
1314
import { injectStore } from './store';
1415
import { NgtAnyRecord } from './types';
1516

@@ -42,15 +43,15 @@ export abstract class NgtHTML {
4243
constructor() {
4344
if (this.domElement === 'gl') {
4445
Object.assign(this.host.nativeElement, {
45-
__ngt_dom_parent__: this.store.snapshot.gl.domElement.parentElement,
46+
[DOM_PARENT]: this.store.snapshot.gl.domElement.parentElement,
4647
});
4748
} else if (this.domElement) {
48-
Object.assign(this.host.nativeElement, { __ngt_dom_parent__: this.domElement });
49+
Object.assign(this.host.nativeElement, { [DOM_PARENT]: this.domElement });
4950
}
5051

5152
this.destroyRef.onDestroy(() => {
52-
(this.host.nativeElement as NgtAnyRecord)['__ngt_dom_parent__'] = null;
53-
delete (this.host.nativeElement as NgtAnyRecord)['__ngt_dom_parent__'];
53+
(this.host.nativeElement as NgtAnyRecord)[DOM_PARENT] = null;
54+
delete (this.host.nativeElement as NgtAnyRecord)[DOM_PARENT];
5455
});
5556
}
5657
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const ROUTED_SCENE = '__ngt_renderer_is_routed_scene__';
22
export const HTML = '__ngt_renderer_is_html';
33
export const NON_ROOT = '__ngt_renderer_is_non_root__';
44
export const SPECIAL_INTERNAL_ADD_COMMENT = '__ngt_renderer_add_comment__';
5+
export const DOM_PARENT = '__ngt_dom_parent__';
56

67
export const SPECIAL_DOM_TAG = {
78
NGT_PORTAL: 'ngt-portal',

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

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import {
1212
import { NgtArgs } from '../directives/args';
1313
import { getLocalState, prepare } from '../instance';
1414
import { NGT_STORE, injectStore, provideStore } from '../store';
15-
import { NgtAnyRecord, NgtInstanceNode, NgtLocalState, NgtState } from '../types';
15+
import { NgtAnyRecord, NgtLocalState, NgtState } from '../types';
1616
import { applyProps } from '../utils/apply-props';
1717
import { is } from '../utils/is';
18-
import { NgtSignalStore, signalStore } from '../utils/signal-store';
18+
import { NgtSignalStore } from '../utils/signal-store';
1919
import { NgtAnyConstructor, injectCatalogue } from './catalogue';
2020
import {
21+
DOM_PARENT,
2122
HTML,
2223
NON_ROOT,
2324
ROUTED_SCENE,
@@ -122,23 +123,9 @@ export class NgtRenderer implements Renderer2 {
122123
}
123124

124125
if (name === SPECIAL_DOM_TAG.NGT_VALUE) {
125-
const instanceStore = signalStore({ parent: null, objects: [], nonObjects: [] });
126126
return createNode(
127127
'three',
128-
Object.assign(
129-
{ __ngt_renderer__: { rawValue: undefined } },
130-
// NOTE: we assign this manually to a raw value node
131-
// because we say it is a 'three' node but we're not using prepare()
132-
{
133-
__ngt__: {
134-
isRaw: true,
135-
instanceStore,
136-
setParent(parent: NgtInstanceNode) {
137-
instanceStore.update({ parent });
138-
},
139-
},
140-
},
141-
),
128+
prepare({ __ngt_renderer__: { rawValue: undefined } }, { store: this.rootStore, isRaw: true }),
142129
this.document,
143130
);
144131
}
@@ -182,8 +169,8 @@ export class NgtRenderer implements Renderer2 {
182169
const comment = this.delegate.createComment(value);
183170

184171
// NOTE: we attach an arrow function to the Comment node
185-
// In our directives, we can call this function to then start tracking the RendererNode
186-
// this is done to limit the amount of Nodes we need to process for getCreationState
172+
// In our directives, we can call this function to then start tracking the RendererNode
173+
// this is done to limit the amount of Nodes we need to process for getCreationState
187174
comment[SPECIAL_INTERNAL_ADD_COMMENT] = (node: NgtRendererNode | 'args') => {
188175
if (node === 'args') {
189176
this.argsCommentNodes.push(comment);
@@ -205,8 +192,8 @@ export class NgtRenderer implements Renderer2 {
205192
) {
206193
addChild(parent, newChild);
207194

208-
if (newChild['__ngt_dom_parent__'] && newChild['__ngt_dom_parent__'] instanceof HTMLElement) {
209-
this.delegate.appendChild(newChild['__ngt_dom_parent__'], newChild);
195+
if (newChild[DOM_PARENT] && newChild[DOM_PARENT] instanceof HTMLElement) {
196+
this.delegate.appendChild(newChild[DOM_PARENT], newChild);
210197
return;
211198
}
212199

@@ -390,17 +377,20 @@ export class NgtRenderer implements Renderer2 {
390377
const localState = getLocalState(el);
391378
if (localState) localState.attach = paths;
392379
}
393-
} else if (name === SPECIAL_PROPERTIES.RAW_VALUE) {
380+
} else {
394381
// NOTE: coercion
395382
let maybeCoerced: string | number | boolean = value;
396383
if (maybeCoerced === '' || maybeCoerced === 'true' || maybeCoerced === 'false') {
397384
maybeCoerced = maybeCoerced === 'true' || maybeCoerced === '';
398385
} else if (!isNaN(Number(maybeCoerced))) {
399386
maybeCoerced = Number(maybeCoerced);
400387
}
401-
rS[NgtRendererClassId.rawValue] = maybeCoerced;
402-
} else {
403-
applyProps(el, { [name]: value });
388+
389+
if (name === SPECIAL_PROPERTIES.RAW_VALUE) {
390+
rS[NgtRendererClassId.rawValue] = maybeCoerced;
391+
} else {
392+
applyProps(el, { [name]: maybeCoerced });
393+
}
404394
}
405395

406396
return false;

0 commit comments

Comments
 (0)