mithril-vndb/archive/v1.0.0-rc.8/api.html
2017-01-26 20:46:32 -05:00

176 lines
6 KiB
HTML

<html>
<head>
<meta charset="UTF-8" />
<title>Mithril.js</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
<link href="lib/prism/prism.css" rel="stylesheet" />
<link href="style.css" rel="stylesheet" />
</head>
<body>
<header>
<section>
<h1>Mithril <small>1.0.0-rc.8</small></h1>
<nav>
<a href="index.html">Guide</a>
<a href="api.html">API</a>
<a href="https://gitter.im/lhorie/mithril.js">Chat</a>
<a href="https://github.com/lhorie/mithril.js">Github</a>
</nav>
</section>
</header>
<main>
<section>
<h1 id="api">API</h1>
<ul>
<li>Core<ul>
<li><a href="hyperscript.html">m</a></li>
<li><a href="render.html">m.render</a></li>
<li><a href="mount.html">m.mount</a></li>
<li><a href="route.html">m.route</a></li>
<li><a href="request.html">m.request</a></li>
<li><a href="jsonp.html">m.jsonp</a></li>
<li><a href="parseQueryString.html">m.parseQueryString</a></li>
<li><a href="buildQueryString.html">m.buildQueryString</a></li>
<li><a href="withAttr.html">m.withAttr</a></li>
<li><a href="trust.html">m.trust</a></li>
<li><a href="fragment.html">m.fragment</a></li>
<li><a href="redraw.html">m.redraw</a></li>
<li><a href="version.html">m.version</a></li>
<li><a href="promise.html">Promise</a></li>
</ul>
</li>
<li>Optional<ul>
<li><a href="stream.html">Stream</a></li>
</ul>
</li>
<li>Tooling<ul>
<li><a href="https://github.com/lhorie/mithril.js/blob/rewrite/ospec">Ospec</a></li>
</ul>
</li>
</ul>
<h3 id="cheatsheet">Cheatsheet</h3>
<p>Here are examples for the most commonly used methods. If a method is not listed below, it&#39;s meant for advanced usage.</p>
<h4 id="m-selector-attrs-children-docs-hyperscript-html-">m(selector, attrs, children) - <a href="hyperscript.html">docs</a></h4>
<pre><code class="lang-javascript">m(&quot;div.class#id&quot;, {title: &quot;title&quot;}, [&quot;children&quot;])
</code></pre>
<hr>
<h4 id="m-mount-element-component-docs-mount-html-">m.mount(element, component) - <a href="mount.html">docs</a></h4>
<pre><code class="lang-javascript">var state = {
count: 0,
inc: function() {state.count++}
}
var Counter = {
view: function() {
return m(&quot;div&quot;, {onclick: state.inc}, state.count)
}
}
m.mount(document.body, Counter)
</code></pre>
<hr>
<h4 id="m-route-root-defaultroute-routes-docs-route-html-">m.route(root, defaultRoute, routes) - <a href="route.html">docs</a></h4>
<pre><code class="lang-javascript">var Home = {
view: function() {
return &quot;Welcome&quot;
}
}
m.route(document.body, &quot;/home&quot;, {
&quot;/home&quot;: Home, // defines `http://localhost/#!/home`
})
</code></pre>
<h4 id="m-route-set-path-docs-route-html-mrouteset-">m.route.set(path) - <a href="route.html#mrouteset">docs</a></h4>
<pre><code class="lang-javascript">m.route.set(&quot;/home&quot;)
</code></pre>
<h4 id="m-route-get-docs-route-html-mrouteget-">m.route.get() - <a href="route.html#mrouteget">docs</a></h4>
<pre><code class="lang-javascript">var currentRoute = m.route.get()
</code></pre>
<h4 id="m-route-prefix-prefix-docs-route-html-mrouteprefix-">m.route.prefix(prefix) - <a href="route.html#mrouteprefix">docs</a></h4>
<p>Call this before <code>m.route()</code></p>
<pre><code class="lang-javascript">m.route.prefix(&quot;#!&quot;)
</code></pre>
<h4 id="m-route-link-docs-route-html-mroutelink-">m.route.link() - <a href="route.html#mroutelink">docs</a></h4>
<pre><code class="lang-javascript">m(&quot;a[href=&#39;/Home&#39;]&quot;, {oncreate: m.route.link}, &quot;Go to home page&quot;)
</code></pre>
<hr>
<h4 id="m-request-options-docs-request-html-">m.request(options) - <a href="request.html">docs</a></h4>
<pre><code class="lang-javascript">m.request({
method: &quot;PUT&quot;,
url: &quot;/api/v1/users/:id&quot;,
data: {id: 1, name: &quot;test&quot;}
})
.then(function(result) {
console.log(result)
})
</code></pre>
<hr>
<h4 id="m-jsonp-options-docs-jsonp-html-">m.jsonp(options) - <a href="jsonp.html">docs</a></h4>
<pre><code class="lang-javascript">m.jsonp({
url: &quot;/api/v1/users/:id&quot;,
data: {id: 1},
callbackKey: &quot;callback&quot;,
})
.then(function(result) {
console.log(result)
})
</code></pre>
<hr>
<h4 id="m-parsequerystring-querystring-docs-parsequerystring-html-">m.parseQueryString(querystring) - <a href="parseQueryString.html">docs</a></h4>
<pre><code class="lang-javascript">var object = m.parseQueryString(&quot;a=1&amp;b=2&quot;)
// {a: &quot;1&quot;, b: &quot;2&quot;}
</code></pre>
<hr>
<h4 id="m-buildquerystring-object-docs-buildquerystring-html-">m.buildQueryString(object) - <a href="buildQueryString.html">docs</a></h4>
<pre><code class="lang-javascript">var querystring = m.buildQueryString({a: &quot;1&quot;, b: &quot;2&quot;})
// &quot;a=1&amp;b=2&quot;
</code></pre>
<hr>
<h4 id="m-withattr-attrname-callback-docs-withattr-html-">m.withAttr(attrName, callback) - <a href="withAttr.html">docs</a></h4>
<pre><code class="lang-javascript">var state = {
value: &quot;&quot;,
setValue: function(v) {state.value = v}
}
var Component = {
view: function() {
return m(&quot;input&quot;, {
oninput: m.withAttr(&quot;value&quot;, state.setValue),
value: state.value,
})
}
}
m.mount(document.body, Component)
</code></pre>
<hr>
<h4 id="m-trust-htmlstring-docs-trust-html-">m.trust(htmlString) - <a href="trust.html">docs</a></h4>
<pre><code class="lang-javascript">m.render(document.body, m.trust(&quot;&lt;h1&gt;Hello&lt;/h1&gt;&quot;))
</code></pre>
<hr>
<h4 id="m-redraw-docs-redraw-html-">m.redraw() - <a href="redraw.html">docs</a></h4>
<pre><code class="lang-javascript">var count = 0
function inc() {
setInterval(function() {
count++
m.redraw()
}, 1000)
}
var Counter = {
oninit: inc,
view: function() {
return m(&quot;div&quot;, count)
}
}
m.mount(document.body, Counter)
</code></pre>
<hr />
<small>License: MIT. &copy; Leo Horie.</small>
</section>
</main>
<script src="lib/prism/prism.js"></script>
</body>
</html