Skip to content

Commit 80c092c

Browse files
refactor(angular): cleanup flexRender and add some jsdocs (#6151)
* refactor(angular): cleanup flexRender and add some jsdocs * add more jsdocs
1 parent 9739893 commit 80c092c

File tree

14 files changed

+791
-370
lines changed

14 files changed

+791
-370
lines changed

packages/angular-table/src/angularReactivityFeature.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,53 @@ declare module '@tanstack/table-core' {
2020
> extends Table_AngularReactivity<TFeatures, TData> {}
2121
}
2222

23+
/**
24+
* Predicate used to skip/ignore a property name when applying Angular reactivity.
25+
*
26+
* Returning `true` means the property should NOT be wrapped/made reactive.
27+
*/
2328
type SkipPropertyFn = (property: string) => boolean
2429

30+
/**
31+
* Fine-grained configuration for Angular reactivity.
32+
*
33+
* Each key controls whether prototype methods/getters on the corresponding TanStack Table
34+
* objects are wrapped with signal-aware access.
35+
*
36+
* - `true` enables wrapping using the default skip rules.
37+
* - `false` disables wrapping entirely for that object type.
38+
* - a function allows customizing the skip rules (see {@link SkipPropertyFn}).
39+
*/
2540
export interface AngularReactivityFlags {
41+
/** Controls reactive wrapping for `Header` instances. */
2642
header: boolean | SkipPropertyFn
43+
/** Controls reactive wrapping for `Column` instances. */
2744
column: boolean | SkipPropertyFn
45+
/** Controls reactive wrapping for `Row` instances. */
2846
row: boolean | SkipPropertyFn
47+
/** Controls reactive wrapping for `Cell` instances. */
2948
cell: boolean | SkipPropertyFn
3049
}
3150

51+
/**
52+
* Table option extension for Angular reactivity.
53+
*
54+
* Available on `createTable` options via module augmentation in this file.
55+
*/
3256
interface TableOptions_AngularReactivity {
57+
/**
58+
* Enables/disables and configures Angular reactivity on table-related prototypes.
59+
*
60+
* If omitted, defaults are provided by the feature.
61+
*/
3362
reactivity?: Partial<AngularReactivityFlags>
3463
}
3564

65+
/**
66+
* Table API extension for Angular reactivity.
67+
*
68+
* Added to the table instance via module augmentation.
69+
*/
3670
interface Table_AngularReactivity<
3771
TFeatures extends TableFeatures,
3872
TData extends RowData,
@@ -42,11 +76,16 @@ interface Table_AngularReactivity<
4276
*/
4377
get: Signal<Table<TFeatures, TData>>
4478
/**
45-
* @internal
79+
* Sets the reactive notifier that powers {@link get}.
80+
*
81+
* @internal Used by the Angular table adapter to connect its notifier to the core table.
4682
*/
4783
setTableNotifier: (signal: Signal<Table<TFeatures, TData>>) => void
4884
}
4985

86+
/**
87+
* Type map describing what this feature adds to TanStack Table constructors.
88+
*/
5089
interface AngularReactivityFeatureConstructors<
5190
TFeatures extends TableFeatures,
5291
TData extends RowData,
@@ -55,6 +94,13 @@ interface AngularReactivityFeatureConstructors<
5594
Table: Table_AngularReactivity<TFeatures, TData>
5695
}
5796

97+
/**
98+
* Resolves the user-provided `reactivity.*` config to a skip predicate.
99+
*
100+
* - `false` is handled by callers (feature method returns early)
101+
* - `true` selects the default predicate
102+
* - a function overrides the default predicate
103+
*/
58104
const getUserSkipPropertyFn = (
59105
value: undefined | null | boolean | SkipPropertyFn,
60106
defaultPropertyFn: SkipPropertyFn,
@@ -147,6 +193,9 @@ function constructAngularReactivityFeature<
147193

148194
export const angularReactivityFeature = constructAngularReactivityFeature()
149195

196+
/**
197+
* Default predicate used to skip base/non-reactive properties.
198+
*/
150199
function skipBaseProperties(property: string): boolean {
151200
return (
152201
// equals `getContext`

packages/angular-table/src/flex-render/context.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ export const FlexRenderComponentProps = new InjectionToken<
44
NonNullable<unknown>
55
>('[@tanstack/angular-table] Flex render component context props')
66

7+
/**
8+
* Inject the flex render context props.
9+
*
10+
* Can be used in components rendered via FlexRender directives.
11+
*/
712
export function injectFlexRenderContext<T extends NonNullable<unknown>>(): T {
813
return inject<T>(FlexRenderComponentProps)
914
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
/**
2-
* Flags used to manage and optimize the rendering lifecycle of content of the cell,
3-
* while using FlexRenderDirective.
2+
* Flags used to manage and optimize the rendering lifecycle of the content of the cell
3+
* while using {@link FlexViewRenderer}.
44
*/
5-
export enum FlexRenderFlags {
5+
export const FlexRenderFlags = {
66
/**
77
* Indicates that the view is being created for the first time or will be cleared during the next update phase.
88
* This is the initial state and will transition after the first ngDoCheck.
99
*/
10-
ViewFirstRender = 1 << 0,
10+
ViewFirstRender: 1 << 0,
1111
/**
1212
* Indicates the `content` property has been modified or the view requires a complete re-render.
1313
* When this flag is enabled, the view will be cleared and recreated from scratch.
1414
*/
15-
ContentChanged = 1 << 1,
15+
ContentChanged: 1 << 1,
1616
/**
1717
* Indicates that the `props` property reference has changed.
1818
* When this flag is enabled, the view context is updated based on the type of the content.
1919
*
2020
* For Component view, inputs will be updated and view will be marked as dirty.
2121
* For TemplateRef and primitive values, view will be marked as dirty
2222
*/
23-
PropsReferenceChanged = 1 << 2,
23+
PropsReferenceChanged: 1 << 2,
2424
/**
2525
* Indicates that the current rendered view needs to be checked for changes.
2626
* This will be set to true when `content(props)` result has changed or during
2727
* forced update
2828
*/
29-
Dirty = 1 << 3,
29+
Dirty: 1 << 3,
3030
/**
3131
* Indicates that the first render effect has been checked at least one time.
3232
*/
33-
RenderEffectChecked = 1 << 4,
34-
}
33+
RenderEffectChecked: 1 << 4,
34+
} as const

packages/angular-table/src/flex-render/flex-render-component.ts renamed to packages/angular-table/src/flex-render/flexRenderComponent.ts

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,13 @@ import type {
77
Type,
88
} from '@angular/core'
99

10-
type Inputs<T> = {
11-
[K in keyof T as T[K] extends InputSignal<infer R>
12-
? K
13-
: never]?: T[K] extends InputSignal<infer R> ? R : never
14-
}
15-
16-
type Outputs<T> = {
17-
[K in keyof T as T[K] extends OutputEmitterRef<infer R>
18-
? K
19-
: never]?: T[K] extends OutputEmitterRef<infer R>
20-
? OutputEmitterRef<R>['emit']
21-
: never
22-
}
23-
24-
type OptionalKeys<T, K = keyof T> = K extends keyof T
25-
? T[K] extends Required<T>[K]
26-
? undefined extends T[K]
27-
? K
28-
: never
29-
: K
30-
: never
31-
32-
interface FlexRenderRequiredOptions<
10+
interface FlexRenderRequiredInputOptions<
3311
TInputs extends Record<string, any>,
3412
TOutputs extends Record<string, any>,
3513
> {
3614
/**
37-
* Component instance inputs. They will be set via [componentRef.setInput API](https://angular.dev/api/core/ComponentRef#setInput)
15+
* Component instance inputs.
16+
* They will be set via [componentRef.setInput API](https://angular.dev/api/core/ComponentRef#setInput)
3817
*/
3918
inputs: TInputs
4019
/**
@@ -52,7 +31,8 @@ interface FlexRenderOptions<
5231
TOutputs extends Record<string, any>,
5332
> {
5433
/**
55-
* Component instance inputs. They will be set via [componentRef.setInput API](https://angular.dev/api/core/ComponentRef#setInput)
34+
* Component instance inputs.
35+
* They will be set via [componentRef.setInput API](https://angular.dev/api/core/ComponentRef#setInput)
5636
*/
5737
inputs?: TInputs
5838
/**
@@ -65,6 +45,28 @@ interface FlexRenderOptions<
6545
injector?: Injector
6646
}
6747

48+
type Inputs<T> = {
49+
[K in keyof T as T[K] extends InputSignal<infer R>
50+
? K
51+
: never]?: T[K] extends InputSignal<infer R> ? R : never
52+
}
53+
54+
type Outputs<T> = {
55+
[K in keyof T as T[K] extends OutputEmitterRef<infer R>
56+
? K
57+
: never]?: T[K] extends OutputEmitterRef<infer R>
58+
? OutputEmitterRef<R>['emit']
59+
: never
60+
}
61+
62+
type OptionalKeys<T, K = keyof T> = K extends keyof T
63+
? T[K] extends Required<T>[K]
64+
? undefined extends T[K]
65+
? K
66+
: never
67+
: K
68+
: never
69+
6870
/**
6971
* Helper function to create a [@link FlexRenderComponent] instance, with better type-safety.
7072
*
@@ -80,7 +82,7 @@ export function flexRenderComponent<
8082
component: Type<TComponent>,
8183
...options: OptionalKeys<TInputs> extends never
8284
? [FlexRenderOptions<TInputs, TOutputs>?]
83-
: [FlexRenderRequiredOptions<TInputs, TOutputs>]
85+
: [FlexRenderRequiredInputOptions<TInputs, TOutputs>]
8486
): FlexRenderComponent<TComponent> {
8587
const { inputs, injector, outputs } = options[0] ?? {}
8688
return new FlexRenderComponent(component, inputs, injector, outputs)

packages/angular-table/src/flex-render/flex-render-component-ref.ts renamed to packages/angular-table/src/flex-render/flexRenderComponentFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
OutputRefSubscription,
1010
ViewContainerRef,
1111
} from '@angular/core'
12-
import { FlexRenderComponent } from './flex-render-component'
12+
import { FlexRenderComponent } from './flexRenderComponent'
1313

1414
@Injectable()
1515
export class FlexRenderComponentFactory {

0 commit comments

Comments
 (0)