141 lines
6.5 KiB
HTML
141 lines
6.5 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>m.deps
|
|
- Mithril</title>
|
|
<meta name="description" value="Mithril.js - a Javascript Framework for Building Brilliant Applications" />
|
|
<link href="lib/prism/prism.css" rel="stylesheet" />
|
|
<link href="style.css" rel="stylesheet" />
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<nav class="container">
|
|
<a href="index.html" class="logo"><span>○</span> Mithril</a>
|
|
<a href="getting-started.html">Guide</a>
|
|
<a href="mithril.html">API</a>
|
|
<a href="community.html">Community</a>
|
|
<a href="http://lhorie.github.io/mithril-blog">Learn</a>
|
|
<a href="installation.html">Download</a>
|
|
<a href="http://github.com/lhorie/mithril.js" target="_blank">Github</a>
|
|
</nav>
|
|
</header>
|
|
<main>
|
|
<section class="content">
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col(3,3,12)">
|
|
<h2 id="api">API (v0.2.1)</h2>
|
|
<h3 id="core">Core</h3>
|
|
<ul>
|
|
<li><a href="mithril.html" title="A utility to create virtual elements">m</a></li>
|
|
<li><a href="mithril.component.html" title="Parameterizes a component">m.component</a></li>
|
|
<li><a href="mithril.mount.html" title="Renders a component">m.mount</a></li>
|
|
<li><a href="mithril.prop.html" title="A getter-setter utility">m.prop</a></li>
|
|
<li><a href="mithril.withAttr.html" title="A event handler factory utility">m.withAttr</a></li>
|
|
</ul>
|
|
<h3 id="routing">Routing</h3>
|
|
<ul>
|
|
<li><a href="mithril.route.html" title="A routing utility">m.route</a>
|
|
<ul>
|
|
<li><a href="mithril.route.html#defining-routes" title="Defines what routes exist">m.route(rootElement, defaultRoute, routes)</a></li>
|
|
<li><a href="mithril.route.html#redirecting" title="Redirects to a route">m.route(path, params, replaceHistory)</a></li>
|
|
<li><a href="mithril.route.html#reading-current-route" title="Read the current route">m.route()</a></li>
|
|
<li><a href="mithril.route.html#mode-abstraction" title="Routing mode abstraction">m.route(element)</a></li>
|
|
<li><a href="mithril.route.html#mode" title="Whether routing uses location hash, querystring or pathname">m.route.mode</a></li>
|
|
<li><a href="mithril.route.html#param" title="Read an argument from a parameterized route">m.route.param</a></li>
|
|
<li><a href="mithril.route.html#buildQueryString" title="Serialize data into querystring format">m.route.buildQueryString</a></li>
|
|
<li><a href="mithril.route.html#parseQueryString" title="Read an argument from a parameterized route">m.route.parseQueryString</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<h3 id="data">Data</h3>
|
|
<ul>
|
|
<li><a href="mithril.request.html" title="A high-level AJAX utility">m.request</a></li>
|
|
<li><a href="mithril.deferred.html" title="A Promise factory">m.deferred</a></li>
|
|
<li><a href="mithril.sync.html" title="A Promise aggregator">m.sync</a></li>
|
|
</ul>
|
|
<h3 id="html">HTML</h3>
|
|
<ul>
|
|
<li><a href="mithril.trust.html" title="A method to unescape HTML">m.trust</a></li>
|
|
</ul>
|
|
<h3 id="rendering">Rendering</h3>
|
|
<ul>
|
|
<li><a href="mithril.render.html" title="The lowest level rendering method">m.render</a></li>
|
|
<li><a href="mithril.redraw.html" title="A high-level explicit rendering method">m.redraw</a>
|
|
<ul>
|
|
<li><a href="mithril.redraw.html#strategy" title="A flag that drives the rendering strategy for the next redraw">m.redraw.strategy(strategy)</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="mithril.computation.html" title="Utilities to integrate asynchronous contexts to the rendering system">m.startComputation / m.endComputation</a></li>
|
|
</ul>
|
|
<h3 id="data">Testing</h3>
|
|
<ul>
|
|
<li><a href="mithril.deps.html" title="The dependency injector">m.deps</a></li>
|
|
</ul>
|
|
|
|
<h2 id="archive">History</h2>
|
|
<ul>
|
|
<li><a href="roadmap.html">Roadmap</a></li>
|
|
<li><a href="change-log.html">Change log</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="col(9,9,12)">
|
|
<h2 id="m-deps">m.deps</h2>
|
|
<hr>
|
|
<ul>
|
|
<li><a href="#usage">Usage</a></li>
|
|
<li><a href="#signature">Signature</a></li>
|
|
</ul>
|
|
<hr>
|
|
<p>This function overwrites the reference to the <code>window</code> object that is used internally by Mithril. It is useful for injecting a mock <code>window</code> dependency for the purposes of testing and for running Mithril in non-browser environments. The mock object used by Mithril for its own test suite <a href="https://github.com/lhorie/mithril.js/blob/next/tests/mock.js">can be found in the development repo</a>.</p>
|
|
<p>By default, Mithril uses <code>window</code> itself as the dependency. Note that Mithril only uses the mock object for browser APIs such as the DOM API and <code>requestAnimationFrame</code>, but relies on the environment for ECMAScript features like <code>Object.keys</code>.</p>
|
|
<hr>
|
|
<h3 id="usage">Usage</h3>
|
|
<p>Call it at the beginning of your test file to supply a mock <code>window</code>:</p>
|
|
<pre><code class="lang-javascript">function testMithril(mockWindow) {
|
|
window = m.deps(mockWindow);
|
|
|
|
// Your tests here...
|
|
}
|
|
</code></pre>
|
|
<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">Window m.deps(Object window)
|
|
|
|
where:
|
|
Window :: Object<any>
|
|
</code></pre>
|
|
<ul>
|
|
<li><p><strong>Object Window</strong></p>
|
|
<p>This should be either <code>window</code> or a mock of the <code>window</code> object.</p>
|
|
<p>Mithril uses certain <code>window</code> methods that will need to be made available for complete test coverage, depending on your application:</p>
|
|
<ul>
|
|
<li><code>window.document</code></li>
|
|
<li>Mithril also uses certain methods on the DOM node object</li>
|
|
<li><code>window.requestAnimationFrame</code>/<code>window.cancelAnimationFrame</code></li>
|
|
<li>Falls back to <code>window.setTimeout</code>/<code>window.clearTimeout</code></li>
|
|
<li><code>window.location</code></li>
|
|
<li><code>window.history</code></li>
|
|
<li><code>window.scrollTo</code></li>
|
|
<li><code>window.XMLHttpRequest</code></li>
|
|
</ul>
|
|
</li>
|
|
<li><p><strong>returns</strong> Window</p>
|
|
<p>The returned window is the same as what is passed in.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
<footer>
|
|
<div class="container">
|
|
Released under the <a href="http://opensource.org/licenses/MIT" target="_blank">MIT license</a>
|
|
<br />© 2014 Leo Horie
|
|
</div>
|
|
</footer>
|
|
<script src="lib/prism/prism.js"></script>
|
|
</body>
|
|
</html>
|