Warning not to invoke background m.request as m.prop in modules
This commit is contained in:
parent
320466edeb
commit
44f6a9a64d
4 changed files with 3212 additions and 10 deletions
3200
archive/v0.1.23/mithril-tests.js
Normal file
3200
archive/v0.1.23/mithril-tests.js
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -81,16 +81,16 @@ todo.Todo = function(data) {
|
||||||
todo.TodoList = Array;</code></pre>
|
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>
|
<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`
|
<pre><code class="lang-javascript">//define a getter-setter with initial value `John`
|
||||||
var name = m.prop("John");
|
var firstName = m.prop("John");
|
||||||
|
|
||||||
//read the value
|
//read the value
|
||||||
var a = name(); //a == "John"
|
var a = firstName(); //a == "John"
|
||||||
|
|
||||||
//set the value to `Mary`
|
//set the value to `Mary`
|
||||||
name("Mary"); //Mary
|
firstName("Mary"); //Mary
|
||||||
|
|
||||||
//read the value
|
//read the value
|
||||||
var b = name(); //b == "Mary"</code></pre>
|
var b = firstName(); //b == "Mary"</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>
|
<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: "Write code"});
|
<pre><code class="lang-javascript">var myTask = new todo.Todo({description: "Write code"});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,16 +64,16 @@
|
||||||
<hr>
|
<hr>
|
||||||
<h3 id="usage">Usage</h3>
|
<h3 id="usage">Usage</h3>
|
||||||
<pre><code class="lang-javascript">//define a getter-setter with initial value `John`
|
<pre><code class="lang-javascript">//define a getter-setter with initial value `John`
|
||||||
var name = m.prop("John");
|
var firstName = m.prop("John");
|
||||||
|
|
||||||
//read the value
|
//read the value
|
||||||
var a = name(); //a == "John"
|
var a = firstName(); //a == "John"
|
||||||
|
|
||||||
//set the value to `Mary`
|
//set the value to `Mary`
|
||||||
name("Mary"); //Mary
|
firstName("Mary"); //Mary
|
||||||
|
|
||||||
//read the value
|
//read the value
|
||||||
var b = name(); //b == "Mary"</code></pre>
|
var b = firstName(); //b == "Mary"</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>
|
<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
|
<pre><code class="lang-javascript">//a contrived example of bi-directional data binding
|
||||||
var user = {
|
var user = {
|
||||||
|
|
|
||||||
|
|
@ -458,6 +458,8 @@ where:
|
||||||
.then(m.redraw); //force redraw
|
.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)
|
- **any unwrapSuccess(any data)** (optional)
|
||||||
|
|
||||||
A preprocessor function to unwrap the data from a success response in case the response contains metadata wrapping the data.
|
A preprocessor function to unwrap the data from a success response in case the response contains metadata wrapping the data.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue