make getter-setters json-serializable
This commit is contained in:
parent
0aba8aa4bd
commit
cb6994dd93
9 changed files with 49 additions and 14 deletions
|
|
@ -61,7 +61,7 @@
|
|||
</div>
|
||||
<div class="col(9,9,12)">
|
||||
<h2 id="m-prop">m.prop</h2>
|
||||
<p>This is a getter-setter factory utility. It returns a function that stores information</p>
|
||||
<p>This is a getter-setter factory utility. It returns a function that stores information.</p>
|
||||
<hr>
|
||||
<h3 id="usage">Usage</h3>
|
||||
<pre><code class="lang-javascript">//define a getter-setter with initial value `John`
|
||||
|
|
@ -101,6 +101,12 @@ m.request({method: "GET", url: "/users"})
|
|||
//then when resolved (e.g. in a view), the `users` getter-setter will contain a list of User instances
|
||||
//i.e. users()[0].name() == "John"</code></pre>
|
||||
<hr>
|
||||
<h3 id="serializing-getter-setters">Serializing getter-setters</h3>
|
||||
<p>Getter-setters are JSON-serializable:</p>
|
||||
<pre><code class="lang-javascript">var data = {foo: m.prop("bar")};
|
||||
JSON.stringify(data); // '{"foo": "bar"}'</code></pre>
|
||||
<p>This allows getter-setters to be passed directly as parameters to <a href="mithril.request.html"><code>m.request</code></a>, for example.</p>
|
||||
<hr>
|
||||
<h3 id="signature">Signature</h3>
|
||||
<p><a href="how-to-read-signatures.html">How to read signatures</a></p>
|
||||
<pre><code class="lang-clike">GetterSetter prop([any initialValue])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue