|
1 | | -<nav><ul><li><a href="/">TinyBase</a></li><li><a href="/api/">API</a></li><li><a href="/api/mergeable-store/"><code>mergeable-store</code></a></li><li><a href="/api/mergeable-store/interfaces/">Interfaces</a></li><li><a href="/api/mergeable-store/interfaces/mergeable/mergeablestore/"><code>MergeableStore</code></a></li><li><a href="/api/mergeable-store/interfaces/mergeable/mergeablestore/methods/setter/">Setter methods</a></li><li><a href="/api/mergeable-store/interfaces/mergeable/mergeablestore/methods/setter/setcontent/"><code>setContent</code></a></li></ul></nav><section class="s1" id="/api/mergeable-store/interfaces/mergeable/mergeablestore/methods/setter/setcontent/" data-id="sC4"><h1><code>setContent</code></h1><p>The <code>setContent</code> method takes an array of two objects and sets the entire data of the <a href="/api/store/interfaces/store/store/"><code>Store</code></a>.</p><pre><code><span class="function"><a href="/api/mergeable-store/interfaces/mergeable/mergeablestore/methods/setter/setcontent/">setContent</a></span><span class="punctuation">(</span>content<span class="operator">:</span> <span class="type"><a href="/api/store/type-aliases/store/content/">Content</a></span><span class="punctuation">)</span><span class="operator">:</span> <span class="keyword">this</span></code></pre><div class="table"><table><tr><th></th><th>Type</th><th>Description</th></tr><tr><th><code>content</code></th><td><code><span class="type"><a href="/api/store/type-aliases/store/content/">Content</a></span></code></td><td><p>An array containing the tabular and keyed-value data of the <a href="/api/store/interfaces/store/store/"><code>Store</code></a> to be set.</p></td></tr><tr><th class="right">returns</th><td><code><span class="keyword">this</span></code></td><td><p></p><p>A reference to the <a href="/api/store/interfaces/store/store/"><code>Store</code></a>.</p><p></p></td></tr></table></div><p>This method will cause listeners to be called for any <a href="/api/store/type-aliases/store/table/"><code>Table</code></a>, <a href="/api/store/type-aliases/store/row/"><code>Row</code></a>, <a href="/api/store/type-aliases/store/cell/"><code>Cell</code></a>, <a href="/api/store/type-aliases/store/value/"><code>Value</code></a>, or <a href="/api/common/type-aliases/identity/id/"><code>Id</code></a> changes resulting from it.</p><p>Any part of the provided objects that are invalid (either according to the <a href="/api/store/type-aliases/store/tables/"><code>Tables</code></a> or <a href="/api/store/type-aliases/store/values/"><code>Values</code></a> type, or because it does not match a <a href="/api/store/type-aliases/schema/tablesschema/"><code>TablesSchema</code></a> or <a href="/api/store/type-aliases/schema/valuesschema/"><code>ValuesSchema</code></a> associated with the <a href="/api/store/interfaces/store/store/"><code>Store</code></a>), will be ignored silently.</p><p>Assuming that at least some of the provided <a href="/api/store/type-aliases/store/tables/"><code>Tables</code></a> object or <a href="/api/store/type-aliases/store/values/"><code>Values</code></a> object is valid, any data that was already present in that part of the <a href="/api/store/interfaces/store/store/"><code>Store</code></a> will be completely overwritten. If either object is completely invalid, no change will be made to the corresponding part of the <a href="/api/store/interfaces/store/store/"><code>Store</code></a>.</p><p>The method returns a reference to the <a href="/api/store/interfaces/store/store/"><code>Store</code></a> so that subsequent operations can be chained in a fluent style.</p><section class="s2"><h2>Examples</h2><p>This example sets the data of a <a href="/api/store/interfaces/store/store/"><code>Store</code></a>.</p><pre><code><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> |
| 1 | +<nav><ul><li><a href="/">TinyBase</a></li><li><a href="/api/">API</a></li><li><a href="/api/mergeable-store/"><code>mergeable-store</code></a></li><li><a href="/api/mergeable-store/interfaces/">Interfaces</a></li><li><a href="/api/mergeable-store/interfaces/mergeable/mergeablestore/"><code>MergeableStore</code></a></li><li><a href="/api/mergeable-store/interfaces/mergeable/mergeablestore/methods/setter/">Setter methods</a></li><li><a href="/api/mergeable-store/interfaces/mergeable/mergeablestore/methods/setter/setcontent/"><code>setContent</code></a></li></ul></nav><section class="s1" id="/api/mergeable-store/interfaces/mergeable/mergeablestore/methods/setter/setcontent/" data-id="sC4"><h1><code>setContent</code></h1><p>The <code>setContent</code> method takes an array of two objects and sets the entire data of the <a href="/api/store/interfaces/store/store/"><code>Store</code></a>.</p><pre><code><span class="function"><a href="/api/mergeable-store/interfaces/mergeable/mergeablestore/methods/setter/setcontent/">setContent</a></span><span class="punctuation">(</span>content<span class="operator">:</span> <span class="type"><a href="/api/store/type-aliases/store/content/">Content</a></span> <span class="operator">|</span> <span class="punctuation">(</span><span class="punctuation">)</span> <span class="operator">=></span> <span class="type"><a href="/api/store/type-aliases/store/content/">Content</a></span><span class="punctuation">)</span><span class="operator">:</span> <span class="keyword">this</span></code></pre><div class="table"><table><tr><th></th><th>Type</th><th>Description</th></tr><tr><th><code>content</code></th><td><code><span class="type"><a href="/api/store/type-aliases/store/content/">Content</a></span> <span class="operator">|</span> <span class="punctuation">(</span><span class="punctuation">)</span> <span class="operator">=></span> <span class="type"><a href="/api/store/type-aliases/store/content/">Content</a></span></code></td><td><p>An array containing the tabular and keyed-value data of the <a href="/api/store/interfaces/store/store/"><code>Store</code></a> to be set, or a function that returns the array.</p></td></tr><tr><th class="right">returns</th><td><code><span class="keyword">this</span></code></td><td><p></p><p>A reference to the <a href="/api/store/interfaces/store/store/"><code>Store</code></a>.</p><p></p></td></tr></table></div><p>This method will cause listeners to be called for any <a href="/api/store/type-aliases/store/table/"><code>Table</code></a>, <a href="/api/store/type-aliases/store/row/"><code>Row</code></a>, <a href="/api/store/type-aliases/store/cell/"><code>Cell</code></a>, <a href="/api/store/type-aliases/store/value/"><code>Value</code></a>, or <a href="/api/common/type-aliases/identity/id/"><code>Id</code></a> changes resulting from it.</p><p>Any part of the provided objects that are invalid (either according to the <a href="/api/store/type-aliases/store/tables/"><code>Tables</code></a> or <a href="/api/store/type-aliases/store/values/"><code>Values</code></a> type, or because it does not match a <a href="/api/store/type-aliases/schema/tablesschema/"><code>TablesSchema</code></a> or <a href="/api/store/type-aliases/schema/valuesschema/"><code>ValuesSchema</code></a> associated with the <a href="/api/store/interfaces/store/store/"><code>Store</code></a>), will be ignored silently.</p><p>Assuming that at least some of the provided <a href="/api/store/type-aliases/store/tables/"><code>Tables</code></a> object or <a href="/api/store/type-aliases/store/values/"><code>Values</code></a> object is valid, any data that was already present in that part of the <a href="/api/store/interfaces/store/store/"><code>Store</code></a> will be completely overwritten. If either object is completely invalid, no change will be made to the corresponding part of the <a href="/api/store/interfaces/store/store/"><code>Store</code></a>.</p><p>The method returns a reference to the <a href="/api/store/interfaces/store/store/"><code>Store</code></a> so that subsequent operations can be chained in a fluent style.</p><p>Since v5.4.2, this method can also take a function that returns the content.</p><section class="s2"><h2>Examples</h2><p>This example sets the data of a <a href="/api/store/interfaces/store/store/"><code>Store</code></a>.</p><pre><code><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> |
2 | 2 |
|
3 | 3 | <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="function"><a href="/api/mergeable-store/interfaces/mergeable/mergeablestore/methods/setter/setcontent/">setContent</a></span><span class="punctuation">(</span><span class="punctuation">[</span> |
4 | 4 | <span class="punctuation">{</span><span class="literal-property">pets</span><span class="operator">:</span> <span class="punctuation">{</span><span class="literal-property">fido</span><span class="operator">:</span> <span class="punctuation">{</span><span class="literal-property">species</span><span class="operator">:</span> <span class="string">'dog'</span><span class="punctuation">}</span><span class="punctuation">}</span><span class="punctuation">}</span><span class="punctuation">,</span> |
|
8 | 8 | <span class="comment">// -> {pets: {fido: {species: 'dog'}}}</span> |
9 | 9 | console<span class="punctuation">.</span><span class="function">log</span><span class="punctuation">(</span>store<span class="punctuation">.</span><span class="function"><a href="/api/mergeable-store/interfaces/mergeable/mergeablestore/methods/getter/getvalues/">getValues</a></span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">)</span><span class="punctuation">;</span> |
10 | 10 | <span class="comment">// -> {open: true, employees: 3}</span> |
| 11 | +</code></pre><p>This example sets the data of a <a href="/api/store/interfaces/store/store/"><code>Store</code></a> with the results of a function.</p><pre><code><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> |
| 12 | + |
| 13 | +<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="function"><a href="/api/mergeable-store/interfaces/mergeable/mergeablestore/methods/setter/setcontent/">setContent</a></span><span class="punctuation">(</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="operator">=></span> <span class="punctuation">[</span> |
| 14 | + <span class="punctuation">{</span><span class="literal-property">pets</span><span class="operator">:</span> <span class="punctuation">{</span><span class="literal-property">fido</span><span class="operator">:</span> <span class="punctuation">{</span><span class="literal-property">species</span><span class="operator">:</span> <span class="string">'dog'</span><span class="punctuation">}</span><span class="punctuation">}</span><span class="punctuation">}</span><span class="punctuation">,</span> |
| 15 | + <span class="punctuation">{</span><span class="literal-property">open</span><span class="operator">:</span> <span class="boolean">true</span><span class="punctuation">,</span> <span class="literal-property">employees</span><span class="operator">:</span> <span class="number">3</span><span class="punctuation">}</span><span class="punctuation">,</span> |
| 16 | +<span class="punctuation">]</span><span class="punctuation">)</span><span class="punctuation">;</span> |
| 17 | +console<span class="punctuation">.</span><span class="function">log</span><span class="punctuation">(</span>store<span class="punctuation">.</span><span class="function"><a href="/api/mergeable-store/interfaces/mergeable/mergeablestore/methods/getter/gettables/">getTables</a></span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">)</span><span class="punctuation">;</span> |
| 18 | +<span class="comment">// -> {pets: {fido: {species: 'dog'}}}</span> |
| 19 | +console<span class="punctuation">.</span><span class="function">log</span><span class="punctuation">(</span>store<span class="punctuation">.</span><span class="function"><a href="/api/mergeable-store/interfaces/mergeable/mergeablestore/methods/getter/getvalues/">getValues</a></span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">)</span><span class="punctuation">;</span> |
| 20 | +<span class="comment">// -> {open: true, employees: 3}</span> |
11 | 21 | </code></pre><p>This example attempts to set the data of an existing <a href="/api/store/interfaces/store/store/"><code>Store</code></a> with partly invalid, and then completely invalid objects.</p><pre><code><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> |
12 | 22 |
|
13 | 23 | <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="function"><a href="/api/mergeable-store/interfaces/mergeable/mergeablestore/methods/setter/setcontent/">setContent</a></span><span class="punctuation">(</span><span class="punctuation">[</span> |
|
0 commit comments