|
| 1 | +/* eslint-disable no-dupe-class-members */ |
1 | 2 | import { MixedStyleDeclaration } from '@native-html/css-processor'; |
2 | 3 | import { ReactNativePropsDefinitions } from '../helper-types'; |
3 | 4 | import { SetMarkersForTNode } from '../tree/tree-types'; |
@@ -240,14 +241,33 @@ export default class HTMLElementModel< |
240 | 241 | } |
241 | 242 |
|
242 | 243 | /** |
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. |
244 | 245 | * |
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. |
246 | 258 | * @typeParam CM - The {@link HTMLContentModel} attached to the new model. |
247 | 259 | */ |
248 | 260 | extend<CM extends HTMLContentModel>( |
249 | 261 | 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>> |
250 | 269 | ): HTMLElementModel<T, CM> { |
| 270 | + const properties = typeof arg === 'function' ? arg(this) : arg; |
251 | 271 | return new HTMLElementModel<T, CM>({ |
252 | 272 | ...this, |
253 | 273 | ...properties |
|
0 commit comments