Warning not to invoke background m.request as m.prop in modules

This commit is contained in:
Barney 2014-11-07 10:23:23 +00:00
parent 320466edeb
commit 44f6a9a64d
4 changed files with 3212 additions and 10 deletions

File diff suppressed because it is too large Load diff

View file

@ -81,16 +81,16 @@ todo.Todo = function(data) {
todo.TodoList = Array;</code></pre>
<p><a href="mithril.prop.html"><code>m.prop</code></a> is simply a factory for a getter-setter function. Getter-setters work like this:</p>
<pre><code class="lang-javascript">//define a getter-setter with initial value `John`
var name = m.prop(&quot;John&quot;);
var firstName = m.prop(&quot;John&quot;);
//read the value
var a = name(); //a == &quot;John&quot;
var a = firstName(); //a == &quot;John&quot;
//set the value to `Mary`
name(&quot;Mary&quot;); //Mary
firstName(&quot;Mary&quot;); //Mary
//read the value
var b = name(); //b == &quot;Mary&quot;</code></pre>
var b = firstName(); //b == &quot;Mary&quot;</code></pre>
<p>Note that the <code>Todo</code> and <code>TodoList</code> classes we defined above are plain vanilla Javascript constructors. They can be initialized and used like this:</p>
<pre><code class="lang-javascript">var myTask = new todo.Todo({description: &quot;Write code&quot;});
@ -442,4 +442,4 @@ this.description = function(value) {
</footer>
<script src="lib/prism/prism.js"></script>
</body>
</html>
</html>

View file

@ -64,16 +64,16 @@
<hr>
<h3 id="usage">Usage</h3>
<pre><code class="lang-javascript">//define a getter-setter with initial value `John`
var name = m.prop(&quot;John&quot;);
var firstName = m.prop(&quot;John&quot;);
//read the value
var a = name(); //a == &quot;John&quot;
var a = firstName(); //a == &quot;John&quot;
//set the value to `Mary`
name(&quot;Mary&quot;); //Mary
firstName(&quot;Mary&quot;); //Mary
//read the value
var b = name(); //b == &quot;Mary&quot;</code></pre>
var b = firstName(); //b == &quot;Mary&quot;</code></pre>
<p>It can be used in conjunction with <a href="mithril.withattr.html"><code>m.withAttr</code></a> to implement data binding in the view-to-model direction and to provide uniform data access for model entity properties.</p>
<pre><code class="lang-javascript">//a contrived example of bi-directional data binding
var user = {
@ -137,4 +137,4 @@ where:
</footer>
<script src="lib/prism/prism.js"></script>
</body>
</html>
</html>

View file

@ -457,6 +457,8 @@ where:
m.request({method: "GET", url: "/foo", background: true})
.then(m.redraw); //force redraw
```
The return value of a background `m.request` should not be exposed to controllers or views, since without the blocking effect of redraw-blocking effect of `m.startComputation` it is liable to be invoked before it resolves, which can lead to runtime errors.
- **any unwrapSuccess(any data)** (optional)