Skip to content

Commit 483fd97

Browse files
committed
fix(core): allow using dotted path for attach array
before: `[attach]="['shadow', 'camera', key]"` after: `[attach]="['shadow.camera', key]"`
1 parent 06c51b2 commit 483fd97

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ import { NgtArgs } from '../directives/args';
1515
import { NgtCommonDirective } from '../directives/common';
1616
import { NgtParent } from '../directives/parent';
1717
import { getInstanceState, prepare } from '../instance';
18-
import { NgtConstructorRepresentation, NgtEventHandlers, NgtInstanceNode, NgtInstanceState } from '../types';
18+
import {
19+
NgtAttachable,
20+
NgtConstructorRepresentation,
21+
NgtEventHandlers,
22+
NgtInstanceNode,
23+
NgtInstanceState,
24+
} from '../types';
1925
import { applyProps } from '../utils/apply-props';
2026
import { is } from '../utils/is';
2127
import { injectCatalogue } from './catalogue';
@@ -595,18 +601,8 @@ export class NgtRenderer2 implements Renderer2 {
595601

596602
// [attach]
597603
if (name === 'attach') {
598-
if (instanceState)
599-
instanceState.attach = Array.isArray(value)
600-
? value.map((v) => v.toString())
601-
: typeof value === 'function'
602-
? value
603-
: typeof value === 'string'
604-
? value.split('.')
605-
: [value];
606-
if (parent) {
607-
untracked(() => attachThreeNodes(parent, el as unknown as NgtInstanceNode));
608-
}
609-
604+
if (instanceState) instanceState.attach = this.normalizeAttach(value);
605+
if (parent) untracked(() => attachThreeNodes(parent, el as unknown as NgtInstanceNode));
610606
return;
611607
}
612608

@@ -761,6 +757,12 @@ export class NgtRenderer2 implements Renderer2 {
761757
return directiveInstance;
762758
}
763759

760+
private normalizeAttach(attach: NgtAttachable) {
761+
if (typeof attach === 'function') return attach;
762+
if (typeof attach === 'string') return attach.split('.');
763+
return attach.flatMap((item) => item.toString().split('.'));
764+
}
765+
764766
addClass = this.delegateRenderer.addClass.bind(this.delegateRenderer);
765767
removeClass = this.delegateRenderer.removeClass.bind(this.delegateRenderer);
766768
setStyle = this.delegateRenderer.setStyle.bind(this.delegateRenderer);

0 commit comments

Comments
 (0)