mirror of
https://github.com/status-im/pluto.git
synced 2026-08-31 20:41:12 +00:00
62 lines
10 KiB
HTML
62 lines
10 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><title>Hook · Pluto</title><meta name="viewport" content="width=device-width"/><meta name="generator" content="Docusaurus"/><meta name="description" content="Hook is the mechanism allowing a specific host to define what (and how) can be extended."/><meta name="docsearch:language" content="en"/><meta property="og:title" content="Hook · Pluto"/><meta property="og:type" content="website"/><meta property="og:url" content="https://status-im.github.io/pluto/index.html"/><meta property="og:description" content="Hook is the mechanism allowing a specific host to define what (and how) can be extended."/><meta name="twitter:card" content="summary"/><link rel="shortcut icon" href="/pluto/img/favicon.png"/><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"/><script type="text/javascript" src="https://buttons.github.io/buttons.js"></script><script type="text/javascript" src="/pluto/js/pluto.js"></script><link rel="stylesheet" href="/pluto/css/prism.css"/><link rel="stylesheet" href="/pluto/css/main.css"/></head><body class="sideNavVisible separateOnPageNav"><div class="fixedHeaderContainer"><div class="headerWrapper wrapper"><header><a href="/pluto/"><img class="logo" src="/pluto/img/logo_white.png" alt="Pluto"/><h2 class="headerTitleWithLogo">Pluto</h2></a><div class="navigationWrapper navigationSlider"><nav class="slidingNav"><ul class="nav-site nav-site-internal"><li class="siteNavGroupActive"><a href="/pluto/docs/Manifesto.html" target="_self">Docs</a></li><li class=""><a href="/pluto/examples.html" target="_self">Examples</a></li><li class=""><a href="/pluto/try.html" target="_self">Try</a></li></ul></nav></div></header></div></div><div class="navPusher"><div class="docMainWrapper wrapper"><div class="container docsNavContainer" id="docsNav"><nav class="toc"><div class="toggleNav"><section class="navWrapper wrapper"><div class="navBreadcrumb wrapper"><div class="navToggle" id="navToggler"><i></i></div><h2><i>›</i><span>Concepts</span></h2><div class="tocToggler" id="tocToggler"><i class="icon-toc"></i></div></div><div class="navGroups"><div class="navGroup"><h3 class="navGroupCategoryTitle">Getting Started</h3><ul><li class="navListItem"><a class="navItem" href="/pluto/docs/Manifesto.html">Manifesto</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/Principles.html">Principles</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Concepts</h3><ul><li class="navListItem"><a class="navItem" href="/pluto/docs/concepts/Anatomy.html">Anatomy of an extension</a></li><li class="navListItem navListItemActive"><a class="navItem" href="/pluto/docs/concepts/Hook.html">Hook</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/concepts/View.html">View</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/concepts/Query.html">Query</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/concepts/Event.html">Event</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/concepts/Registry.html">Registry</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Build</h3><ul><li class="navListItem"><a class="navItem" href="/pluto/docs/build/Packaging.html">Packaging</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/build/Deployment.html">Deployment</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/build/FirstExtension.html">My first extension</a></li></ul></div><div class="navGroup"><h3 class="navGroupCategoryTitle">Contributing</h3><ul><li class="navListItem"><a class="navItem" href="/pluto/docs/Development.html">Development</a></li><li class="navListItem"><a class="navItem" href="/pluto/docs/Roadmap.html">Roadmap</a></li></ul></div></div></section></div><script>
|
||
document.addEventListener('DOMContentLoaded', function() {
|
||
createToggler('#navToggler', '#docsNav', 'docsSliderActive');
|
||
createToggler('#tocToggler', 'body', 'tocActive');
|
||
|
||
const headings = document.querySelector('.toc-headings');
|
||
headings && headings.addEventListener('click', function(event) {
|
||
if (event.target.tagName === 'A') {
|
||
document.body.classList.remove('tocActive');
|
||
}
|
||
}, false);
|
||
|
||
function createToggler(togglerSelector, targetSelector, className) {
|
||
var toggler = document.querySelector(togglerSelector);
|
||
var target = document.querySelector(targetSelector);
|
||
|
||
if (!toggler) {
|
||
return;
|
||
}
|
||
|
||
toggler.onclick = function(event) {
|
||
event.preventDefault();
|
||
|
||
target.classList.toggle(className);
|
||
};
|
||
}
|
||
});
|
||
</script></nav></div><div class="container mainContainer docMainContainer"><div class="wrapper"><div class="post"><header class="postHeader"><h1 class="postHeaderTitle">Hook</h1></header><article><div><span><p>Hook is the mechanism allowing a specific host to define what (and how) can be extended.</p>
|
||
<p>Available hooks are defined as part of capacities by maps detailing properties and their associated type. They leverage <a href="Reference">references</a> to use various extensions elements.</p>
|
||
<pre><code class="hljs css language-clojure"><span class="token punctuation">{</span><span class="token operator">:capacities</span> <span class="token punctuation">{</span>hooks/main.my-hook <span class="token punctuation">{</span><span class="token operator">:properties</span> <span class="token punctuation">{</span><span class="token operator">:view</span> <span class="token operator">:view</span> <span class="token operator">:name</span> <span class="token operator">:string</span><span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token punctuation">}</span>
|
||
</code></pre>
|
||
<p>Properties are defined as map of property name (<code>keyword</code>) / property types.</p>
|
||
<p>Type can be:</p>
|
||
<ul>
|
||
<li><code>:string</code>, <code>:keyword</code></li>
|
||
<li>references to <code>:view</code>, <code>:event</code> or <code>:query</code></li>
|
||
<li>one of a set: <code>{:one-of #{:one :two}}</code></li>
|
||
<li>subset of: <code>#{:one :two :three}</code></li>
|
||
<li>complex types <code>{:child {:name :string}}</code> and <code>{:children [{:name :string}]}</code></li>
|
||
</ul>
|
||
<p>Extensions can then specify hooks that will match associated host capacities.
|
||
Hooks implemented by extensions must be qualified with an extra id. This id will be globally unique across all extensions per hook.
|
||
e.g. an extension implementing <code>hooks/main</code> could define a hook with id <code>hooks/main.demo</code>.</p>
|
||
<p>A hook is defined by a map that consists of a number of pairs specific to each extension type. As shown below, the <code>hooks/main.demo</code> hook requires two additional keys: <code>name</code> and <code>view</code>.</p>
|
||
<pre><code class="hljs css language-clojure"><span class="token punctuation">{</span><span class="token keyword">meta</span>
|
||
<span class="token punctuation">{</span><span class="token operator">:name</span> <span class="token string">""</span>
|
||
<span class="token keyword">..</span>.<span class="token punctuation">}</span>
|
||
|
||
views/main
|
||
<span class="token punctuation">[</span>text <span class="token punctuation">{</span><span class="token punctuation">}</span>
|
||
<span class="token string">""</span><span class="token punctuation">]</span>
|
||
|
||
hooks/main.demo
|
||
<span class="token punctuation">{</span><span class="token operator">:view</span> @views/main
|
||
<span class="token operator">:name</span> <span class="token string">"test"</span><span class="token punctuation">}</span><span class="token punctuation">}</span>
|
||
</code></pre>
|
||
<p>Once a host has loaded a valid extension with matching hooks, it can query the resulting map.</p>
|
||
<h2><a class="anchor" aria-hidden="true" id="references"></a><a href="#references" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>References</h2>
|
||
<h3><a class="anchor" aria-hidden="true" id="views"></a><a href="#views" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Views</h3>
|
||
<p>Views references are resolved as a function of one argument that returns hiccup data.
|
||
The argument must be a map of key/value pairs. This map is used as value for <code>properties</code> reference available in <code>let</code> blocks.</p>
|
||
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="/pluto/docs/concepts/Anatomy.html"><span class="arrow-prev">← </span><span>Previous</span></a><a class="docs-next button" href="/pluto/docs/concepts/View.html"><span>Next</span><span class="arrow-next"> →</span></a></div></div></div><nav class="onPageNav docOnPageNav"><ul class="toc-headings"><li><a href="#references">References</a><ul class="toc-headings"><li><a href="#views">Views</a></li></ul></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/pluto/" class="nav-home"><img src="/pluto/img/logo_white.png" alt="Pluto" width="66" height="58"/></a><div><h5>Docs</h5><a href="docs/Tutorial">Getting Started</a><a href="docs/API">API Reference</a></div><div><h5>Community</h5><a href="https://chat.status.im">Project Chat</a><a href="https://twitter.com/ethstatus" target="_blank" rel="noreferrer noopener">Twitter</a></div><div><h5>More</h5><a href="https://blog.status.im/">Blog</a><a href="https://github.com/status-im/pluto/">GitHub</a></div></section><section class="copyright">Copyright © 2018 Status.im</section></footer></div></body></html> |