|
| 1 | +# render$ Directive |
| 2 | + |
| 3 | +The `render$` directive is a Vue directive that dynamically renders Stream or Observable values to DOM element text content. |
| 4 | + |
| 5 | +::: info Note |
| 6 | +Using the directive to render streams will not trigger component updates, only trigger element updates, similar to [signals](https://github.com/tc39/proposal-signals) |
| 7 | +::: |
| 8 | + |
| 9 | +## Syntax |
| 10 | + |
| 11 | +```vue |
| 12 | +<div v-render$="stream$"></div> |
| 13 | +``` |
| 14 | + |
| 15 | +## Examples |
| 16 | + |
| 17 | +### Stream |
| 18 | + |
| 19 | +```vue |
| 20 | +<template> |
| 21 | + <div> |
| 22 | + <div v-render$="message$"></div> |
| 23 | + <button @click="updateMessage">Update Message</button> |
| 24 | + </div> |
| 25 | +</template> |
| 26 | +
|
| 27 | +<script setup> |
| 28 | +import { $, render$ } from "fluth-vue"; |
| 29 | +
|
| 30 | +const vRender$ = render$; |
| 31 | +
|
| 32 | +const message$ = $("Hello World"); |
| 33 | +
|
| 34 | +const updateMessage = () => { |
| 35 | + message$.next("Message updated!"); |
| 36 | +}; |
| 37 | +</script> |
| 38 | +``` |
| 39 | + |
| 40 | +### Observable |
| 41 | + |
| 42 | +```vue |
| 43 | +<template> |
| 44 | + <div> |
| 45 | + <div v-render$="processedData$"></div> |
| 46 | + <button @click="updateData">Update Data</button> |
| 47 | + </div> |
| 48 | +</template> |
| 49 | +
|
| 50 | +<script setup> |
| 51 | +import { $, render$ } from "fluth-vue"; |
| 52 | +
|
| 53 | +const vRender$ = render$; |
| 54 | +
|
| 55 | +const rawData$ = $("raw data"); |
| 56 | +const processedData$ = rawData$.then((data) => `Processed: ${data}`); |
| 57 | +
|
| 58 | +const updateData = () => { |
| 59 | + rawData$.next("new data"); |
| 60 | +}; |
| 61 | +</script> |
| 62 | +``` |
| 63 | + |
| 64 | +### Chained Operations |
| 65 | + |
| 66 | +```vue |
| 67 | +<template> |
| 68 | + <!-- ✅ Good performance, only object$.value.attr.name change will trigger re-render --> |
| 69 | + <div v-render$="object$.pipe(get((v) => v.attr.name))"></div> |
| 70 | +
|
| 71 | + <!-- ❌ bad performance, object$ change will trigger re-render, but attr name change will not --> |
| 72 | + <div v-render$="object$.then((v) => v.attr.name)"></div> |
| 73 | +</template> |
| 74 | +
|
| 75 | +<script setup> |
| 76 | +import { $, get, render$ } from "fluth-vue"; |
| 77 | +
|
| 78 | +const vRender$ = render$; |
| 79 | +
|
| 80 | +const object$ = $({ id: 1, attr: { name: "fluth", age: 18 } }); |
| 81 | +</script> |
| 82 | +``` |
0 commit comments