الأمثلة
أمثلة عملية، وعروض حيّة.
اختر مثالًا لتفتحه بملء الشاشة: المعاينة الحية وكوده المصدري جنبًا إلى جنب.
اختر مثالًا لتفتحه بملء الشاشة: المعاينة الحية وكوده المصدري جنبًا إلى جنب.
عدّل الاسم. النص الثابت يُحدَّد وقت بناء العنصر، أما الديناميكي فيُعاد حسابه مع كل update(). وforceUpdate() يعيد بناء الشجرة، فيتحدّث الثابت أيضًا.
static: Hello, Alice
dynamic: Hello, Alice
import 'nuclo' let name = 'Alice' let host: Element | undefined const Greeting = () => div( input({ value: () => name, onInput: (e) => { name = e.currentTarget.value; update() }, }), p('static: ', `Hello, ${name}`), // built once p('dynamic: ', () => `Hello, ${name}`), // runs on every update() ) export const App = () => div( div({ onMount: (el) => { host = el as unknown as Element } }, Greeting()), // Calls Greeting() again and patches the same nodes: the static text // catches up. The explicit form rebuilds only this tree. button('forceUpdate()', { onClick: () => { if (host) forceUpdate(Greeting(), host) }, }), )