Skip to content

Commit b2a4318

Browse files
committed
Update docs
1 parent 217ccae commit b2a4318

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

docs/component-model/structure.md

+25-16
Original file line numberDiff line numberDiff line change
@@ -286,19 +286,17 @@ define({
286286
});
287287
```
288288
289-
## `render`
289+
## Rendering
290290
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.
292292
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()`.
294294
295295
### Element's Content
296296
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:
298298
299299
```javascript
300-
import { define, html } from "hybrids";
301-
302300
define({
303301
tag: "my-element",
304302
name: "",
@@ -310,9 +308,9 @@ define({
310308
311309
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:
312310
313-
```javascript
314-
import { define, html } from "hybrids";
311+
The template with styles:
315312
313+
```javascript
316314
define({
317315
tag: "my-element",
318316
name: "",
@@ -325,11 +323,22 @@ define({
325323
});
326324
```
327325
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.
329338
330339
### Explicit Mode
331340
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:
333342
334343
```ts
335344
// Disable Shadow DOM
@@ -339,14 +348,14 @@ render: {
339348
...
340349
}
341350

342-
// Enable Shadow DOM
351+
// Force Shadow DOM
343352
render: {
344353
value: (host) => html`...`,
345354
shadow: true,
346355
}
347356
```
348357
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:
350359
351360
```javascript
352361
import { define, html } from "hybrids";
@@ -355,14 +364,14 @@ define({
355364
tag: "my-element",
356365
render: {
357366
value: html`<div>...</div>`,
358-
options: { mode: "close", delegatesFocus: true },
367+
shadow: { mode: "close", delegatesFocus: true },
359368
},
360369
});
361370
```
362371
363372
### Reference Internals
364373
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.
366375
367376
```javascript
368377
import { define, html } from "hybrids";
@@ -387,8 +396,8 @@ define({
387396
console.log("connected");
388397
return () => console.log("disconnected");
389398
},
390-
observe(host, value, lastValue) {
391-
console.log(`${value} -> ${lastValue}`);
399+
observe(host) {
400+
console.log("rendered");
392401
},
393402
},
394403
});

0 commit comments

Comments
 (0)