Skip to content

Commit 8f0b4b7

Browse files
committed
wip: skipBaseProperties skip properties that ends with Handler, pass skip custom fn from table options
1 parent 7e1bb1e commit 8f0b4b7

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

packages/angular-table/src/angularReactivityFeature.ts

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ declare module '@tanstack/table-core' {
2020
> extends Table_AngularReactivity<TFeatures, TData> {}
2121
}
2222

23+
type SkipPropertyFn = (property: string) => boolean
24+
2325
export interface AngularReactivityFlags {
24-
header: boolean
25-
column: boolean
26-
row: boolean
27-
cell: boolean
28-
table: boolean
26+
header: boolean | SkipPropertyFn
27+
column: boolean | SkipPropertyFn
28+
row: boolean | SkipPropertyFn
29+
cell: boolean | SkipPropertyFn
30+
table: boolean | SkipPropertyFn
2931
}
3032

3133
interface TableOptions_AngularReactivity {
@@ -48,6 +50,16 @@ interface AngularReactivityFeatureConstructors<
4850
Table: Table_AngularReactivity<TFeatures, TData>
4951
}
5052

53+
const getUserSkipPropertyFn = (
54+
value: undefined | null | boolean | SkipPropertyFn,
55+
defaultPropertyFn: SkipPropertyFn,
56+
) => {
57+
if (typeof value === 'boolean') {
58+
return defaultPropertyFn
59+
}
60+
return value ?? defaultPropertyFn
61+
}
62+
5163
export function constructAngularReactivityFeature<
5264
TFeatures extends TableFeatures,
5365
TData extends RowData,
@@ -80,7 +92,10 @@ export function constructAngularReactivityFeature<
8092
}
8193
markReactive(table)
8294
setReactiveProps(table.get, table, {
83-
skipProperty: skipBaseProperties,
95+
skipProperty: getUserSkipPropertyFn(
96+
table.options.reactivity?.table,
97+
skipBaseProperties,
98+
),
8499
})
85100
},
86101

@@ -90,7 +105,10 @@ export function constructAngularReactivityFeature<
90105
}
91106
markReactive(cell)
92107
setReactiveProps(cell._table.get, cell, {
93-
skipProperty: skipBaseProperties,
108+
skipProperty: getUserSkipPropertyFn(
109+
cell._table.options.reactivity?.cell,
110+
skipBaseProperties,
111+
),
94112
})
95113
},
96114

@@ -100,7 +118,10 @@ export function constructAngularReactivityFeature<
100118
}
101119
markReactive(column)
102120
setReactiveProps(column._table.get, column, {
103-
skipProperty: skipBaseProperties,
121+
skipProperty: getUserSkipPropertyFn(
122+
column._table.options.reactivity?.cell,
123+
skipBaseProperties,
124+
),
104125
})
105126
},
106127

@@ -110,7 +131,10 @@ export function constructAngularReactivityFeature<
110131
}
111132
markReactive(header)
112133
setReactiveProps(header._table.get, header, {
113-
skipProperty: skipBaseProperties,
134+
skipProperty: getUserSkipPropertyFn(
135+
header._table.options.reactivity?.cell,
136+
skipBaseProperties,
137+
),
114138
})
115139
},
116140

@@ -120,7 +144,10 @@ export function constructAngularReactivityFeature<
120144
}
121145
markReactive(row)
122146
setReactiveProps(row._table.get, row, {
123-
skipProperty: skipBaseProperties,
147+
skipProperty: getUserSkipPropertyFn(
148+
row._table.options.reactivity?.cell,
149+
skipBaseProperties,
150+
),
124151
})
125152
},
126153
}
@@ -134,7 +161,7 @@ function skipBaseProperties(property: string): boolean {
134161
property === 'getContext' ||
135162
// start with `_`
136163
property[0] === '_' ||
137-
// doesn't start with `get`
164+
// doesn't start with `get`, but faster
138165
!(property[0] === 'g' && property[1] === 'e' && property[2] === 't') ||
139166
// ends with `Handler`
140167
property.endsWith('Handler')

0 commit comments

Comments
 (0)