Skip to content

Commit

Permalink
deploy: c2a19cd
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoprietog committed Jun 21, 2024
1 parent 4007407 commit 9cef42a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions handbook/drive.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ <h2 id="canceling-visits-before-they-start"><a class="anchor" href="#canceling-v
<p>Restoration visits cannot be canceled and do not fire <code>turbo:before-visit</code>. Turbo Drive issues restoration visits in response to history navigation that has <em>already taken place</em>, typically via the browser’s Back or Forward buttons.</p>
<h2 id="custom-rendering"><a class="anchor" href="#custom-rendering"></a> Custom Rendering</h2>
<p>Applications can customize the rendering process by adding a document-wide <code>turbo:before-render</code> event listener and overriding the <code>event.detail.render</code> property.</p>
<p>For example, you could merge the response document’s <code>&lt;body&gt;</code> element into the requesting document’s <code>&lt;body&gt;</code> element with <a href="https://github.com/patrick-steele-idem/morphdom">morphdom</a>:</p>
<pre class="language-javascript"><code class="language-javascript"><span class="token keyword">import</span> morphdom <span class="token keyword">from</span> <span class="token string">"morphdom"</span><br><br><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">"turbo:before-render"</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token parameter">event</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span><br> event<span class="token punctuation">.</span>detail<span class="token punctuation">.</span><span class="token function-variable function">render</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">currentElement<span class="token punctuation">,</span> newElement</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span><br> <span class="token function">morphdom</span><span class="token punctuation">(</span>currentElement<span class="token punctuation">,</span> newElement<span class="token punctuation">)</span><br> <span class="token punctuation">}</span><br><span class="token punctuation">}</span><span class="token punctuation">)</span></code></pre>
<p>For example, you could merge the response document’s <code>&lt;body&gt;</code> element into the requesting document’s <code>&lt;body&gt;</code> element with <a href="https://github.com/bigskysoftware/idiomorph">idiomorph</a> or <a href="https://github.com/patrick-steele-idem/morphdom">morphdom</a>:</p>
<pre class="language-javascript"><code class="language-javascript"><span class="token keyword">import</span> <span class="token punctuation">{</span> Idiomorph <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"idiomorph"</span><br><br><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">"turbo:before-render"</span><span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token parameter">event</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span><br> event<span class="token punctuation">.</span>detail<span class="token punctuation">.</span><span class="token function-variable function">render</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">currentElement<span class="token punctuation">,</span> newElement</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span><br> Idiomorph<span class="token punctuation">.</span><span class="token function">morph</span><span class="token punctuation">(</span>currentElement<span class="token punctuation">,</span> newElement<span class="token punctuation">)</span><br> <span class="token punctuation">}</span><br><span class="token punctuation">}</span><span class="token punctuation">)</span></code></pre>
<h2 id="pausing-rendering"><a class="anchor" href="#pausing-rendering"></a> Pausing Rendering</h2>
<p>Applications can pause rendering and make additional preparations before continuing.</p>
<p>Listen for the <code>turbo:before-render</code> event to be notified when rendering is about to start, and pause it using <code>event.preventDefault()</code>. Once the preparation is done continue rendering by calling <code>event.detail.resume()</code>.</p>
Expand Down

0 comments on commit 9cef42a

Please sign in to comment.