MCPcopy Index your code
hub / github.com/TanStack/table / FlexRenderDirective

Class FlexRenderDirective

packages/angular-table/src/flex-render.ts:55–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53 providers: [FlexRenderComponentFactory],
54})
55export class FlexRenderDirective<TProps extends NonNullable<unknown>>
56 implements OnChanges, DoCheck
57{
58 readonly #flexRenderComponentFactory = inject(FlexRenderComponentFactory)
59 readonly #changeDetectorRef = inject(ChangeDetectorRef)
60
61 @Input({ required: true, alias: 'flexRender' })
62 content:
63 | number
64 | string
65 | ((props: TProps) => FlexRenderContent<TProps>)
66 | null
67 | undefined = undefined
68
69 @Input({ required: true, alias: 'flexRenderProps' })
70 props: TProps = {} as TProps
71
72 @Input({ required: false, alias: 'flexRenderInjector' })
73 injector: Injector = inject(Injector)
74
75 renderFlags = FlexRenderFlags.ViewFirstRender
76 renderView: FlexRenderView<
77 FlexRenderViewAllowedType,
78 FlexRenderTypedContent
79 > | null = null
80
81 readonly #latestContent = () => {
82 const { content, props } = this
83 return typeof content !== 'function'
84 ? content
85 : runInInjectionContext(this.injector, () => content(props))
86 }
87
88 #getContentValue = memo(
89 () => [this.#latestContent(), this.props, this.content],
90 (latestContent) => {
91 return mapToFlexRenderTypedContent(latestContent)
92 },
93 { key: 'flexRenderContentValue', debug: () => false },
94 )
95
96 constructor(
97 @Inject(ViewContainerRef)
98 private readonly viewContainerRef: ViewContainerRef,
99 @Inject(TemplateRef)
100 private readonly templateRef: TemplateRef<any>,
101 ) {}
102
103 ngOnChanges(changes: SimpleChanges) {
104 if (changes['props']) {
105 this.renderFlags |= FlexRenderFlags.PropsReferenceChanged
106 }
107 if (changes['content']) {
108 this.renderFlags |=
109 FlexRenderFlags.ContentChanged | FlexRenderFlags.ViewFirstRender
110 this.update()
111 }
112 }

Callers

nothing calls this directly

Calls 3

memoFunction · 0.90
contentFunction · 0.85

Tested by

no test coverage detected