Skip to content

Commit

Permalink
docs: v0.3.20
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyfrc committed May 26, 2024
1 parent 942b4e5 commit 0fb71e3
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 18 deletions.
39 changes: 39 additions & 0 deletions docs/api/observable_store.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
## Functions

<dl>
<dt><a href="#slice">slice(store, options)</a> ⇒ <code>Object</code></dt>
<dd><p>Creates a slice of the store with its own state and actions, namespaced to avoid conflicts.</p>
</dd>
<dt><a href="#store">store(initialState, [options])</a> ⇒ <code><a href="#ObservableStore">ObservableStore</a></code></dt>
<dd><p>This function creates a new instance of ObservableStore with the provided initial state and enhances it with localStorage support if enabled. The store&#39;s state will be automatically persisted to and loaded from localStorage, using the provided name as the key. The <code>localStorage</code> option enables this behavior and can be toggled off if persistence is not needed.</p>
</dd>
Expand Down Expand Up @@ -253,6 +256,42 @@ Use this method to dispatch redux-style actions or flux actions, triggering stat
// Dispatching an action with a payload
CartStore.dispatch('add', { id: 1, name: 'Product 1', quantity: 2 });
```
<a name="slice"></a>

## slice(store, options) ⇒ <code>Object</code>
Creates a slice of the store with its own state and actions, namespaced to avoid conflicts.

**Kind**: global function
**Returns**: <code>Object</code> - - An object containing the action methods for the slice.

| Param | Type | Description |
| --- | --- | --- |
| store | <code>Object</code> | The main store instance. |
| options | <code>Object</code> | The options for creating the slice. |
| options.name | <code>string</code> | The name of the slice. |
| options.state | <code>Object</code> | The initial state of the slice. |
| options.actions | <code>Object</code> | The actions for the slice. |

**Example**
```javascript
const userSlice = slice(appStore, {
name: 'user',
state: {
userInfo: null,
isLoggedIn: false,
},
actions: {
login(state, userInfo) {
state.userInfo = userInfo;
state.isLoggedIn = true;
},
logout(state) {
state.userInfo = null;
state.isLoggedIn = false;
},
}
});
```
<a name="store"></a>

## store(initialState, [options]) ⇒ [<code>ObservableStore</code>](#ObservableStore)
Expand Down
6 changes: 3 additions & 3 deletions docs/javascripts/cami.cdn.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/javascripts/cami.cdn.js.map

Large diffs are not rendered by default.

91 changes: 86 additions & 5 deletions site/api/observable_store/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,15 @@
</ul>
</nav>

</li>

<li class="md-nav__item">
<a href="#slicestore-options-object" class="md-nav__link">
<span class="md-ellipsis">
slice(store, options) ⇒ Object
</span>
</a>

</li>

<li class="md-nav__item">
Expand Down Expand Up @@ -1480,6 +1489,15 @@
</ul>
</nav>

</li>

<li class="md-nav__item">
<a href="#slicestore-options-object" class="md-nav__link">
<span class="md-ellipsis">
slice(store, options) ⇒ Object
</span>
</a>

</li>

<li class="md-nav__item">
Expand Down Expand Up @@ -1519,6 +1537,9 @@ <h2 id="classes">Classes</h2>

<h2 id="functions">Functions</h2>
<dl>
<dt><a href="#slice">slice(store, options)</a><code>Object</code></dt>
<dd><p>Creates a slice of the store with its own state and actions, namespaced to avoid conflicts.</p>
</dd>
<dt><a href="#store">store(initialState, [options])</a><code><a href="#ObservableStore">ObservableStore</a></code></dt>
<dd><p>This function creates a new instance of ObservableStore with the provided initial state and enhances it with localStorage support if enabled. The store&#39;s state will be automatically persisted to and loaded from localStorage, using the provided name as the key. The <code>localStorage</code> option enables this behavior and can be toggled off if persistence is not needed.</p>
</dd>
Expand Down Expand Up @@ -1872,6 +1893,66 @@ <h3 id="observablestoredispatchaction-payload">ObservableStore.dispatch(action,
<div class="language-javascript highlight"><pre><span></span><code><span id="__span-5-1"><a id="__codelineno-5-1" name="__codelineno-5-1" href="#__codelineno-5-1"></a><span class="c1">// Dispatching an action with a payload</span>
</span><span id="__span-5-2"><a id="__codelineno-5-2" name="__codelineno-5-2" href="#__codelineno-5-2"></a><span class="nx">CartStore</span><span class="p">.</span><span class="nx">dispatch</span><span class="p">(</span><span class="s1">&#39;add&#39;</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nx">id</span><span class="o">:</span><span class="w"> </span><span class="mf">1</span><span class="p">,</span><span class="w"> </span><span class="nx">name</span><span class="o">:</span><span class="w"> </span><span class="s1">&#39;Product 1&#39;</span><span class="p">,</span><span class="w"> </span><span class="nx">quantity</span><span class="o">:</span><span class="w"> </span><span class="mf">2</span><span class="w"> </span><span class="p">});</span>
</span></code></pre></div>
<a name="slice"></a></p>
<h2 id="slicestore-options-object">slice(store, options) ⇒ <code>Object</code></h2>
<p>Creates a slice of the store with its own state and actions, namespaced to avoid conflicts.</p>
<p><strong>Kind</strong>: global function<br />
<strong>Returns</strong>: <code>Object</code> - - An object containing the action methods for the slice. </p>
<table>
<thead>
<tr>
<th>Param</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>store</td>
<td><code>Object</code></td>
<td>The main store instance.</td>
</tr>
<tr>
<td>options</td>
<td><code>Object</code></td>
<td>The options for creating the slice.</td>
</tr>
<tr>
<td>options.name</td>
<td><code>string</code></td>
<td>The name of the slice.</td>
</tr>
<tr>
<td>options.state</td>
<td><code>Object</code></td>
<td>The initial state of the slice.</td>
</tr>
<tr>
<td>options.actions</td>
<td><code>Object</code></td>
<td>The actions for the slice.</td>
</tr>
</tbody>
</table>
<p><strong>Example</strong><br />
<div class="language-javascript highlight"><pre><span></span><code><span id="__span-6-1"><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="kd">const</span><span class="w"> </span><span class="nx">userSlice</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">slice</span><span class="p">(</span><span class="nx">appStore</span><span class="p">,</span><span class="w"> </span><span class="p">{</span>
</span><span id="__span-6-2"><a id="__codelineno-6-2" name="__codelineno-6-2" href="#__codelineno-6-2"></a><span class="w"> </span><span class="nx">name</span><span class="o">:</span><span class="w"> </span><span class="s1">&#39;user&#39;</span><span class="p">,</span>
</span><span id="__span-6-3"><a id="__codelineno-6-3" name="__codelineno-6-3" href="#__codelineno-6-3"></a><span class="w"> </span><span class="nx">state</span><span class="o">:</span><span class="w"> </span><span class="p">{</span>
</span><span id="__span-6-4"><a id="__codelineno-6-4" name="__codelineno-6-4" href="#__codelineno-6-4"></a><span class="w"> </span><span class="nx">userInfo</span><span class="o">:</span><span class="w"> </span><span class="kc">null</span><span class="p">,</span>
</span><span id="__span-6-5"><a id="__codelineno-6-5" name="__codelineno-6-5" href="#__codelineno-6-5"></a><span class="w"> </span><span class="nx">isLoggedIn</span><span class="o">:</span><span class="w"> </span><span class="kc">false</span><span class="p">,</span>
</span><span id="__span-6-6"><a id="__codelineno-6-6" name="__codelineno-6-6" href="#__codelineno-6-6"></a><span class="w"> </span><span class="p">},</span>
</span><span id="__span-6-7"><a id="__codelineno-6-7" name="__codelineno-6-7" href="#__codelineno-6-7"></a><span class="w"> </span><span class="nx">actions</span><span class="o">:</span><span class="w"> </span><span class="p">{</span>
</span><span id="__span-6-8"><a id="__codelineno-6-8" name="__codelineno-6-8" href="#__codelineno-6-8"></a><span class="w"> </span><span class="nx">login</span><span class="p">(</span><span class="nx">state</span><span class="p">,</span><span class="w"> </span><span class="nx">userInfo</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
</span><span id="__span-6-9"><a id="__codelineno-6-9" name="__codelineno-6-9" href="#__codelineno-6-9"></a><span class="w"> </span><span class="nx">state</span><span class="p">.</span><span class="nx">userInfo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">userInfo</span><span class="p">;</span>
</span><span id="__span-6-10"><a id="__codelineno-6-10" name="__codelineno-6-10" href="#__codelineno-6-10"></a><span class="w"> </span><span class="nx">state</span><span class="p">.</span><span class="nx">isLoggedIn</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="p">;</span>
</span><span id="__span-6-11"><a id="__codelineno-6-11" name="__codelineno-6-11" href="#__codelineno-6-11"></a><span class="w"> </span><span class="p">},</span>
</span><span id="__span-6-12"><a id="__codelineno-6-12" name="__codelineno-6-12" href="#__codelineno-6-12"></a><span class="w"> </span><span class="nx">logout</span><span class="p">(</span><span class="nx">state</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
</span><span id="__span-6-13"><a id="__codelineno-6-13" name="__codelineno-6-13" href="#__codelineno-6-13"></a><span class="w"> </span><span class="nx">state</span><span class="p">.</span><span class="nx">userInfo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">null</span><span class="p">;</span>
</span><span id="__span-6-14"><a id="__codelineno-6-14" name="__codelineno-6-14" href="#__codelineno-6-14"></a><span class="w"> </span><span class="nx">state</span><span class="p">.</span><span class="nx">isLoggedIn</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="p">;</span>
</span><span id="__span-6-15"><a id="__codelineno-6-15" name="__codelineno-6-15" href="#__codelineno-6-15"></a><span class="w"> </span><span class="p">},</span>
</span><span id="__span-6-16"><a id="__codelineno-6-16" name="__codelineno-6-16" href="#__codelineno-6-16"></a><span class="w"> </span><span class="p">}</span>
</span><span id="__span-6-17"><a id="__codelineno-6-17" name="__codelineno-6-17" href="#__codelineno-6-17"></a><span class="p">});</span>
</span></code></pre></div>
<a name="store"></a></p>
<h2 id="storeinitialstate-options-observablestore">store(initialState, [options]) ⇒ <a href="#ObservableStore"><code>ObservableStore</code></a></h2>
<p>This function creates a new instance of ObservableStore with the provided initial state and enhances it with localStorage support if enabled. The store's state will be automatically persisted to and loaded from localStorage, using the provided name as the key. The <code>localStorage</code> option enables this behavior and can be toggled off if persistence is not needed.</p>
Expand Down Expand Up @@ -1920,11 +2001,11 @@ <h2 id="storeinitialstate-options-observablestore">store(initialState, [options]
</tbody>
</table>
<p><strong>Example</strong><br />
<div class="language-javascript highlight"><pre><span></span><code><span id="__span-6-1"><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="c1">// Create a store with default localStorage support</span>
</span><span id="__span-6-2"><a id="__codelineno-6-2" name="__codelineno-6-2" href="#__codelineno-6-2"></a><span class="kd">const</span><span class="w"> </span><span class="nx">CartStore</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">store</span><span class="p">({</span><span class="w"> </span><span class="nx">cartItems</span><span class="o">:</span><span class="w"> </span><span class="p">[]</span><span class="w"> </span><span class="p">});</span>
</span><span id="__span-6-3"><a id="__codelineno-6-3" name="__codelineno-6-3" href="#__codelineno-6-3"></a>
</span><span id="__span-6-4"><a id="__codelineno-6-4" name="__codelineno-6-4" href="#__codelineno-6-4"></a><span class="c1">// Create a store without localStorage support</span>
</span><span id="__span-6-5"><a id="__codelineno-6-5" name="__codelineno-6-5" href="#__codelineno-6-5"></a><span class="kd">const</span><span class="w"> </span><span class="nx">NonPersistentStore</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">store</span><span class="p">({</span><span class="w"> </span><span class="nx">items</span><span class="o">:</span><span class="w"> </span><span class="p">[]</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nx">localStorage</span><span class="o">:</span><span class="w"> </span><span class="kc">false</span><span class="w"> </span><span class="p">});</span>
<div class="language-javascript highlight"><pre><span></span><code><span id="__span-7-1"><a id="__codelineno-7-1" name="__codelineno-7-1" href="#__codelineno-7-1"></a><span class="c1">// Create a store with default localStorage support</span>
</span><span id="__span-7-2"><a id="__codelineno-7-2" name="__codelineno-7-2" href="#__codelineno-7-2"></a><span class="kd">const</span><span class="w"> </span><span class="nx">CartStore</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">store</span><span class="p">({</span><span class="w"> </span><span class="nx">cartItems</span><span class="o">:</span><span class="w"> </span><span class="p">[]</span><span class="w"> </span><span class="p">});</span>
</span><span id="__span-7-3"><a id="__codelineno-7-3" name="__codelineno-7-3" href="#__codelineno-7-3"></a>
</span><span id="__span-7-4"><a id="__codelineno-7-4" name="__codelineno-7-4" href="#__codelineno-7-4"></a><span class="c1">// Create a store without localStorage support</span>
</span><span id="__span-7-5"><a id="__codelineno-7-5" name="__codelineno-7-5" href="#__codelineno-7-5"></a><span class="kd">const</span><span class="w"> </span><span class="nx">NonPersistentStore</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">store</span><span class="p">({</span><span class="w"> </span><span class="nx">items</span><span class="o">:</span><span class="w"> </span><span class="p">[]</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nx">localStorage</span><span class="o">:</span><span class="w"> </span><span class="kc">false</span><span class="w"> </span><span class="p">});</span>
</span></code></pre></div></p>


Expand Down
6 changes: 3 additions & 3 deletions site/javascripts/cami.cdn.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions site/javascripts/cami.cdn.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion site/search/search_index.json

Large diffs are not rendered by default.

Binary file modified site/sitemap.xml.gz
Binary file not shown.

0 comments on commit 0fb71e3

Please sign in to comment.