From 9a3551c57527ae0fc02c7eeb4322f300377c1454 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Tue, 15 Nov 2016 10:16:01 -0500 Subject: [PATCH] add note about synchronicity --- docs/render.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/render.md b/docs/render.md index a1b09c3a..60eaf784 100644 --- a/docs/render.md +++ b/docs/render.md @@ -1,7 +1,8 @@ # render(element, vnodes) - [API](#api) -- [How it works](#how it works) +- [How it works](#how-it-works) +- [Why Virtual DOM](#why-virtual-dom) - [Differences from other API methods](#differences-from-other-api-methods) - [Standalone usage](#standalone-usage) @@ -23,7 +24,13 @@ Argument | Type | Required | Description ### How it works -The `m.render(element, vnodes)` method takes a virtual DOM tree (typically generated via the [`m()` hyperscript function](hyperscript.md), generates a DOM tree and mounts it on `element`. If `element` already has a DOM tree mounted via a previous `m.render()` call, `vnodes` is diffed against the previous `vnodes` tree and the existing DOM tree is modified only where needed to reflect the changes. Unchanged DOM nodes are not touched at all. +The `m.render(element, vnodes)` method takes a virtual DOM tree (typically generated via the [`m()` hyperscript function](hyperscript.md), generates a DOM tree and mounts it on `element`. If `element` already has a DOM tree mounted via a previous `m.render()` call, `vnodes` is diffed against the previous `vnodes` tree and the existing DOM tree is modified only where needed to reflect the changes. Unchanged DOM nodes are not touched at all. + +`m.render` is synchronous. + +--- + +### Why Virtual DOM It may seem wasteful to generate a vnode tree on every redraw, but as it turns out, creating and comparing Javascript data structures is surprisingly cheap compared to reading and modifying the DOM.