You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h2id="integrating-with-the-auto-redrawing-system">Integrating with The Auto-Redrawing System</h2>
50
+
<p>If you need to do custom asynchronous calls without using Mithril's API, and find that your views are not redrawing, or that you're being forced to call <ahref="mithril.redraw.html"><code>m.redraw</code></a> manually, you should consider using <code>m.startComputation</code> / <code>m.endComputation</code> so that Mithril can intelligently auto-redraw once your custom code finishes running.</p>
51
+
<p>In order to integrate asynchronous code to Mithril's autoredrawing system, you should call <code>m.startComputation</code> BEFORE making an asynchronous call, and <code>m.endComputation</code> after the asynchronous callback completes.</p>
52
+
<pre><codeclass="lang-javascript">//this service waits 1 second, logs "hello" and then notifies the view that
53
+
//it may start redrawing (if no other asynchronous operations are pending)
54
+
var doStuff = function() {
55
+
m.startComputation(); //call `startComputation` before the asynchronous `setTimeout`
56
+
57
+
setTimeout(function() {
58
+
console.log("hello");
59
+
60
+
m.endComputation(); //call `endComputation` at the end of the callback
61
+
}, 1000);
62
+
};</code></pre>
63
+
<p>To integrate synchronous code, call <code>m.startComputation</code> at the beginning of the method, and <code>m.endComputation</code> at the end.</p>
m.startComputation(); //call before everything else in the event handler
66
+
67
+
doStuff();
68
+
69
+
m.endComputation(); //call after everything else in the event handler
70
+
}</code></pre>
71
+
<p>For each <code>m.startComputation</code> call a library makes, it MUST also make one and ONLY one corresponding <code>m.endComputation</code> call.</p>
72
+
<p>You should not use these methods if your code is intended to run repeatedly (e.g. by using <code>setInterval</code>). If you want to repeatedly redraw the view without necessarily waiting for user input, you should manually call <ahref="mithril.redraw.html"><code>m.redraw</code></a> within the repeatable context.</p>
<p>When <ahref="integration.html">integrating with third party libraries</a>, you might find that you need to call asynchronous methods from outside of Mithril's API.</p>
76
+
<p>In order to integrate non-trivial asynchronous code to Mithril's auto-redrawing system, you need to ensure all execution threads call <code>m.startComputation</code> / <code>m.endComputation</code>.</p>
77
+
<p>An execution thread is basically any amount of code that runs before other asynchronous threads start to run.</p>
78
+
<p>Integrating multiple execution threads can be done in a two different ways: in a layered fashion or in comprehensive fashion</p>
<p>Layered integration is recommended for modular code where many different APIs may be put together at the application level.</p>
81
+
<p>Below is an example where various methods implemented with a third party library can be integrated in layered fashion: any of the methods can be used in isolation or in combination.</p>
82
+
<p>Notice how <code>doBoth</code> repeatedly calls <code>m.startComputation</code> since that method calls both <code>doSomething</code> and <code>doAnother</code>. This is perfectly valid: there are three asynchronous computations pending after the <code>jQuery.when</code> method is called, and therefore, three pairs of <code>m.startComputation</code> / <code>m.endComputation</code> in play.</p>
<p>Comprehensive integration is recommended if integrating a monolithic series of asynchronous operations. In contrast to layered integration, it minimizes the number of <code>m.startComputation</code> / <code>m.endComputation</code> to avoid clutter.</p>
111
+
<p>The example below shows a convoluted series of AJAX requests implemented with a third party library.</p>
<li>Mithril is now available at <ahref="http://cdnjs.com/libraries/mithril/">cdnjs</a> and <ahref="http://www.jsdelivr.com/#!mithril">jsdelivr</a></li>
70
+
</ul>
71
+
<h3id="bug-fixes-">Bug Fixes:</h3>
72
+
<ul>
73
+
<li><code>m.route.param</code> now resets on route change correctly <ahref="https://github.com/lhorie/mithril.js/issues/15">#15</a></li>
74
+
<li><code>m.render</code> now correctly ignores undefined values in the virtual tree<ahref="https://github.com/lhorie/mithril.js/issues/16">#16</a></li>
75
+
<li>errors thrown in promises now cause downstreams to be rejected <ahref="https://github.com/lhorie/mithril.js/issues/1">#1</a></li>
76
+
</ul>
77
+
<h3id="breaking-changes-">Breaking changes:</h3>
78
+
<ul>
79
+
<li><p>changed default value for <code>xhr.withCredentials</code> from <code>true</code> to <code>false</code> for <code>m.request</code>, since public APIs are more common than auth-walled ones. <ahref="https://github.com/lhorie/mithril.js/issues/14">#14</a></p>
80
+
<p>In order to configure this flag, the following configuration should be used:</p>
0 commit comments