You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/component-model/structure.md
+25-16
Original file line number
Diff line number
Diff line change
@@ -286,19 +286,17 @@ define({
286
286
});
287
287
```
288
288
289
-
## `render`
289
+
## Rendering
290
290
291
-
The `render` property is reserved for the creating a structure of the custom element. The `value` option must be a function, which returns a result of the call to the built-in template engine.
291
+
The `render` property is reserved for the creating structure of the custom element. The `value` option must be a function, which returns a result of the call to the built-in template engine.
292
292
293
-
The library uses internally the `observe` pattern to call the function automatically when dependencies change. As the property resolves to the update function, it can also be called manually, by `el.render()` or `el.content()`.
293
+
The library uses the `observe` pattern to call the function automatically when dependencies change. As the property resolves to the update function, it can also be called manually, by `el.render()`.
294
294
295
295
### Element's Content
296
296
297
-
By default `render` property updates the content of the custom element:
297
+
By default `render` property creates and updates the content of the custom element:
298
298
299
299
```javascript
300
-
import { define, html } from"hybrids";
301
-
302
300
define({
303
301
tag:"my-element",
304
302
name:"",
@@ -310,9 +308,9 @@ define({
310
308
311
309
If the root template of the element includes styles (`css` and `style` helpers, or `<style>` elements) or `<slot>` element, the library will render the content to the shadow DOM:
312
310
313
-
```javascript
314
-
import { define, html } from"hybrids";
311
+
The template with styles:
315
312
313
+
```javascript
316
314
define({
317
315
tag:"my-element",
318
316
name:"",
@@ -325,11 +323,22 @@ define({
325
323
});
326
324
```
327
325
328
-
!> Templates are compiled lazy, so only the root template can be used to determine the rendering mode. If your nested template includes styles or slots, you must use the `shadow` option to force rendering in the Shadow DOM
326
+
The template with `<slot>` element:
327
+
328
+
```javascript
329
+
define({
330
+
tag:"my-element",
331
+
render: () =>html`
332
+
<slot></slot>
333
+
`,
334
+
});
335
+
```
336
+
337
+
Templates are compiled "just in time", so only the root template can be used to determine the rendering mode. If your nested template includes styles or slots, you must use the `shadow` option to force rendering in the Shadow DOM explicitly.
329
338
330
339
### Explicit Mode
331
340
332
-
Use unique`shadow` option of the `render` property to force rendering in Shadow DOM or element's content:
341
+
Use the`shadow` option of the `render` property to set rendering mode to Shadow DOM or element's content:
333
342
334
343
```ts
335
344
// Disable Shadow DOM
@@ -339,14 +348,14 @@ render: {
339
348
...
340
349
}
341
350
342
-
//Enable Shadow DOM
351
+
//Force Shadow DOM
343
352
render: {
344
353
value: (host) =>html`...`,
345
354
shadow:true,
346
355
}
347
356
```
348
357
349
-
You can use `shadow` option for passing custom argument to the `host.attachShadow()` method:
358
+
You can use this option for passing custom values to the `host.attachShadow()` method:
350
359
351
360
```javascript
352
361
import { define, html } from"hybrids";
@@ -355,14 +364,14 @@ define({
355
364
tag:"my-element",
356
365
render: {
357
366
value:html`<div>...</div>`,
358
-
options: { mode:"close", delegatesFocus:true },
367
+
shadow: { mode:"close", delegatesFocus:true },
359
368
},
360
369
});
361
370
```
362
371
363
372
### Reference Internals
364
373
365
-
The `render` property can be used to reference internals of the custom element. The DOM update process is asynchronous, so to avoid rendering timing issues, always use a property as a reference to the target element. If the property depending on `render` is called before the first update, the update will be triggered manually by calling the function.
374
+
The `render` property can be used to reference internals of the custom element. The DOM update process is asynchronous, so to avoid rendering timing issues, always use the property as a reference to the target element. If the property depending on `render` is called before the first update, the update will be triggered manually by calling the function.
0 commit comments