-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"tests":7461,"assertions":33209,"lines":{"total":2286,"covered":2286,"skipped":0,"pct":100},"statements":{"total":2468,"covered":2468,"skipped":0,"pct":100},"functions":{"total":986,"covered":986,"skipped":0,"pct":100},"branches":{"total":854,"covered":854,"skipped":0,"pct":100},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}} | ||
{"tests":7463,"assertions":33200,"lines":{"total":2288,"covered":2288,"skipped":0,"pct":100},"statements":{"total":2472,"covered":2472,"skipped":0,"pct":100},"functions":{"total":988,"covered":988,"skipped":0,"pct":100},"branches":{"total":854,"covered":854,"skipped":0,"pct":100},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}} |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<nav><ul><li><a href="/">TinyBase</a></li><li><a href="/api/">API</a></li><li><a href="/api/ui-react/"><code>ui-react</code></a></li><li><a href="/api/ui-react/functions/">Functions</a></li><li><a href="/api/ui-react/functions/store-hooks/">Store hooks</a></li><li><a href="/api/ui-react/functions/store-hooks/usestores/"><code>useStores</code></a></li></ul></nav><section class="s1" id="/api/ui-react/functions/store-hooks/usestores/" data-id="uS2"><h1><code>useStores</code></h1><p>The <code>useStores</code> hook is used to get a reference to all the <a href="/api/store/interfaces/store/store/"><code>Store</code></a> objects named by <a href="/api/common/type-aliases/identity/id/"><code>Id</code></a> within a <a href="/api/ui-react/functions/context-components/provider/"><code>Provider</code></a> component context.</p><pre><code><span class="function"><a href="/api/ui-react/functions/store-hooks/usestores/">useStores</a></span><span class="punctuation">(</span><span class="punctuation">)</span><span class="operator">:</span> <span class="punctuation">{</span><span class="punctuation">[</span>storeId<span class="operator">:</span> <span class="type"><a href="/api/common/type-aliases/identity/id/">Id</a></span><span class="punctuation">]</span><span class="operator">:</span> <span class="type"><a href="/api/store/interfaces/store/store/">Store</a></span><span class="punctuation">}</span></code></pre><div class="table"><table><tr><th class="right">returns</th><td><code><span class="punctuation">{</span><span class="punctuation">[</span>storeId<span class="operator">:</span> <span class="type"><a href="/api/common/type-aliases/identity/id/">Id</a></span><span class="punctuation">]</span><span class="operator">:</span> <span class="type"><a href="/api/store/interfaces/store/store/">Store</a></span><span class="punctuation">}</span></code></td><td><p></p><p>An object containing all the <a href="/api/store/interfaces/store/store/"><code>Store</code></a> objects named by <a href="/api/common/type-aliases/identity/id/"><code>Id</code></a>.</p><p></p></td></tr></table></div><p>A <a href="/api/ui-react/functions/context-components/provider/"><code>Provider</code></a> component is used to wrap part of an application in a context. It can contain a default <a href="/api/store/interfaces/store/store/"><code>Store</code></a> (or a set of <a href="/api/store/interfaces/store/store/"><code>Store</code></a> objects named by <a href="/api/common/type-aliases/identity/id/"><code>Id</code></a>) that can be easily accessed without having to be passed down as props through every component.</p><p>The <code>useStores</code> hook lets you get a reference to the latter as an object.</p><section class="s2"><h2>Example</h2><p>This example creates a Provider context into which a <a href="/api/store/interfaces/store/store/"><code>Store</code></a> is provided, named by <a href="/api/common/type-aliases/identity/id/"><code>Id</code></a>. A component within it then uses the <code>useStores</code> hook to get a reference to the <a href="/api/store/interfaces/store/store/"><code>Store</code></a> again.</p><pre><code><span class="keyword">import</span> <span class="punctuation">{</span>Provider<span class="punctuation">,</span> useStores<span class="punctuation">}</span> <span class="keyword">from</span> <span class="string">'tinybase/ui-react'</span><span class="punctuation">;</span> | ||
<span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span><span class="punctuation">;</span> | ||
<span class="keyword">import</span> <span class="punctuation">{</span>createRoot<span class="punctuation">}</span> <span class="keyword">from</span> <span class="string">'react-dom/client'</span><span class="punctuation">;</span> | ||
<span class="keyword">import</span> <span class="punctuation">{</span>createStore<span class="punctuation">}</span> <span class="keyword">from</span> <span class="string">'tinybase'</span><span class="punctuation">;</span> | ||
|
||
<span class="keyword">const</span> <span class="function-variable">App</span> <span class="operator">=</span> <span class="punctuation">(</span><span class="parameter"><span class="punctuation">{</span>store<span class="punctuation">}</span></span><span class="punctuation">)</span> <span class="operator">=></span> <span class="punctuation">(</span> | ||
<span class="tag"><span class="tag"><span class="punctuation"><</span><span class="class-name"><a href="/api/ui-react/functions/context-components/provider/">Provider</a></span></span> <span class="attr-name">storesById</span><span class="script"><span class="script-punctuation">=</span><span class="punctuation">{</span><span class="punctuation">{</span><span class="literal-property">petStore</span><span class="operator">:</span> store<span class="punctuation">}</span><span class="punctuation">}</span></span><span class="punctuation">></span></span><span class="plain-text"> | ||
</span><span class="tag"><span class="tag"><span class="punctuation"><</span><span class="class-name">Pane</span></span> <span class="punctuation">/></span></span><span class="plain-text"> | ||
</span><span class="tag"><span class="tag"><span class="punctuation"></</span><span class="class-name"><a href="/api/ui-react/functions/context-components/provider/">Provider</a></span></span><span class="punctuation">></span></span> | ||
<span class="punctuation">)</span><span class="punctuation">;</span> | ||
<span class="keyword">const</span> <span class="function-variable">Pane</span> <span class="operator">=</span> <span class="punctuation">(</span><span class="punctuation">)</span> <span class="operator">=></span> <span class="punctuation">(</span> | ||
<span class="tag"><span class="tag"><span class="punctuation"><</span>span</span><span class="punctuation">></span></span><span class="punctuation">{</span><span class="function"><a href="/api/ui-react/functions/store-hooks/usestores/">useStores</a></span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">[</span><span class="string">'petStore'</span><span class="punctuation">]</span><span class="punctuation">.</span><span class="function"><a href="/api/store/interfaces/store/store/methods/development/getlistenerstats/">getListenerStats</a></span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">.</span>tables<span class="punctuation">}</span><span class="tag"><span class="tag"><span class="punctuation"></</span>span</span><span class="punctuation">></span></span> | ||
<span class="punctuation">)</span><span class="punctuation">;</span> | ||
|
||
<span class="keyword">const</span> store <span class="operator">=</span> <span class="function"><a href="/api/store/functions/creation/createstore/">createStore</a></span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> | ||
<span class="keyword">const</span> app <span class="operator">=</span> document<span class="punctuation">.</span><span class="function">createElement</span><span class="punctuation">(</span><span class="string">'div'</span><span class="punctuation">)</span><span class="punctuation">;</span> | ||
<span class="function">createRoot</span><span class="punctuation">(</span>app<span class="punctuation">)</span><span class="punctuation">.</span><span class="function">render</span><span class="punctuation">(</span><span class="tag"><span class="tag"><span class="punctuation"><</span><span class="class-name">App</span></span> <span class="attr-name">store</span><span class="script"><span class="script-punctuation">=</span><span class="punctuation">{</span>store<span class="punctuation">}</span></span> <span class="punctuation">/></span></span><span class="punctuation">)</span><span class="punctuation">;</span> | ||
console<span class="punctuation">.</span><span class="function">log</span><span class="punctuation">(</span>app<span class="punctuation">.</span>innerHTML<span class="punctuation">)</span><span class="punctuation">;</span> | ||
<span class="comment">// -> '<span>0</span>'</span> | ||
</code></pre></section><section class="s2"><h2>Since</h2><p>v5.4.1</p></section></section> |
Large diffs are not rendered by default.