Skip to content

Commit ab7019f

Browse files
committed
feat(tre): allow HTMLElementModel.extend to take a merge function
1 parent 8065dd1 commit ab7019f

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

packages/transient-render-engine/src/model/HTMLElementModel.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-dupe-class-members */
12
import { MixedStyleDeclaration } from '@native-html/css-processor';
23
import { ReactNativePropsDefinitions } from '../helper-types';
34
import { SetMarkersForTNode } from '../tree/tree-types';
@@ -240,14 +241,33 @@ export default class HTMLElementModel<
240241
}
241242

242243
/**
243-
* Create a new {@link HTMLElementModel} by merging properties into this model.
244+
* Create a new {@link HTMLElementModel} by shallow-merging properties into this model.
244245
*
245-
* @param properties - The {@link HTMLElementModelProperties} to merge into this model.
246+
* @param merger - A function to generate the new properties to shallwo-merge into this model.
247+
* @typeParam CM - The {@link HTMLContentModel} attached to the new model.
248+
*/
249+
extend<CM extends HTMLContentModel>(
250+
merger: (
251+
properties: HTMLElementModelProperties<T, CM>
252+
) => Partial<HTMLElementModelProperties<T, CM>>
253+
): HTMLElementModel<T, CM>;
254+
/**
255+
* Create a new {@link HTMLElementModel} by shallow-merging properties into this model.
256+
*
257+
* @param properties - The {@link HTMLElementModelProperties} to shallow-merge into this model.
246258
* @typeParam CM - The {@link HTMLContentModel} attached to the new model.
247259
*/
248260
extend<CM extends HTMLContentModel>(
249261
properties: Partial<HTMLElementModelProperties<T, CM>>
262+
): HTMLElementModel<T, CM>;
263+
extend<CM extends HTMLContentModel>(
264+
arg:
265+
| ((
266+
fields: HTMLElementModel<T, M>
267+
) => Partial<HTMLElementModelProperties<T, CM>>)
268+
| Partial<HTMLElementModelProperties<T, CM>>
250269
): HTMLElementModel<T, CM> {
270+
const properties = typeof arg === 'function' ? arg(this) : arg;
251271
return new HTMLElementModel<T, CM>({
252272
...this,
253273
...properties

0 commit comments

Comments
 (0)