From 5ec440da215abbe0464fc585aef6e0617b363dc0 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Tue, 28 Apr 2015 16:23:38 -0400 Subject: [PATCH] add more caveats to docs --- docs/mithril.component.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/mithril.component.md b/docs/mithril.component.md index 59e8884c..552d1a98 100644 --- a/docs/mithril.component.md +++ b/docs/mithril.component.md @@ -497,9 +497,7 @@ If a component A contains another component B that calls asynchronous services, One important limitation to be aware of when using components is that you cannot call Mithril's redrawing methods ([`m.startComputation` / `m.endComputation`](mithril.computation.md) and [`m.redraw`](mithril.redraw.md)) from templates. -In addition, you cannot call `m.request` from templates. - -Doing so will trigger another redraw, which will result in an infinite loop. +In addition, you cannot call `m.request` from templates. Doing so will trigger another redraw, which will result in an infinite loop. There are a few other technical caveats when nesting components: @@ -507,6 +505,18 @@ There are a few other technical caveats when nesting components: 2. Nested components cannot change `m.redraw.strategy` from the controller constructor (but they can from event handlers). It's recommended that you use the [`ctx.retain`](mithril.md#persising-dom-elements-across-route-changes) flag instead of changing the redraw strategy in controller constructors. +3. The root DOM element in a component's view must not be changed during the lifecycle of the component, otherwise undefined behavior will occur. In other words, don't do this: + + ```javascript + var MyComponent = { + view: function() { + return someCondition ? m("a") : m("b") + } + } + ``` + +4. If a component's root element is a subtree directive on its first rendering pass, undefined behavior will occur. + --- ### Opting out of the auto redrawing system