<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Store Class Reference</title>
    <link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="../css/highlight.css" />
    <meta charset='utf-8'>
    <script src="../js/jquery.min.js" defer></script>
    <script src="../js/jazzy.js" defer></script>
    
  </head>
  <body>
    <a name="//apple_ref/swift/Class/Store" class="dashAnchor"></a>
    <a title="Store Class Reference"></a>
    <header>
      <div class="content-wrapper">
        <p><a href="../index.html">Katana Docs</a> (100% documented)</p>
        <p class="header-right"><a href="https://github.com/BendingSpoons/katana-swift"><img src="../img/gh.png"/>View on GitHub</a></p>
      </div>
    </header>
    <div class="content-wrapper">
      <p id="breadcrumbs">
        <a href="../index.html">Katana Reference</a>
        <img id="carat" src="../img/carat.png" />
        Store Class Reference
      </p>
    </div>
    <div class="content-wrapper">
      <nav class="sidebar">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a href="../Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Classes/EmptySideEffectDependencyContainer.html">EmptySideEffectDependencyContainer</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/Node.html">Node</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/PlasticNode.html">PlasticNode</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/PlasticView.html">PlasticView</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/Renderer.html">Renderer</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/Store.html">Store</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/ViewsContainer.html">ViewsContainer</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Enums.html">Enums</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Enums/AnimationType.html">AnimationType</a>
              </li>
              <li class="nav-group-task">
                <a href="../Enums/AsyncActionState.html">AsyncActionState</a>
              </li>
              <li class="nav-group-task">
                <a href="../Enums.html#/s:O6Katana9EmptyKeys">EmptyKeys</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Extensions.html">Extensions</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Extensions/Array.html">Array</a>
              </li>
              <li class="nav-group-task">
                <a href="../Extensions/CGSize.html">CGSize</a>
              </li>
              <li class="nav-group-task">
                <a href="../Extensions/UIView.html">UIView</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Protocols.html">Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Protocols/Action.html">Action</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/ActionWithSideEffect.html">ActionWithSideEffect</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/AnyAsyncAction.html">AnyAsyncAction</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/AnyConnectedNodeDescription.html">AnyConnectedNodeDescription</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/AnyNode.html">AnyNode</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/AnyNodeDescription.html">AnyNodeDescription</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/AnyNodeDescriptionProps.html">AnyNodeDescriptionProps</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/AnyNodeDescriptionWithChildren.html">AnyNodeDescriptionWithChildren</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/AnyPlasticNodeDescription.html">AnyPlasticNodeDescription</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/AnyStore.html">AnyStore</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/AsyncAction.html">AsyncAction</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/Childrenable.html">Childrenable</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/ConnectedNodeDescription.html">ConnectedNodeDescription</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/LinkeableAction.html">LinkeableAction</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/NodeDescription.html">NodeDescription</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/NodeDescriptionProps.html">NodeDescriptionProps</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/NodeDescriptionState.html">NodeDescriptionState</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/NodeDescriptionWithChildren.html">NodeDescriptionWithChildren</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/PlasticNodeDescription.html">PlasticNodeDescription</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/PlasticReferenceSizeable.html">PlasticReferenceSizeable</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/PlatformNativeView.html">PlatformNativeView</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/SideEffectDependencyContainer.html">SideEffectDependencyContainer</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/State.html">State</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Structs.html">Structs</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Structs/ActionLinker.html">ActionLinker</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/ActionLinks.html">ActionLinks</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/Anchor.html">Anchor</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/Anchor/Kind.html">– Kind</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/Animation.html">Animation</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/AnimationContainer.html">AnimationContainer</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/AnimationOptions.html">AnimationOptions</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/AnimationProps.html">AnimationProps</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/ChildrenAnimations.html">ChildrenAnimations</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/EdgeInsets.html">EdgeInsets</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/EmptyProps.html">EmptyProps</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/EmptyState.html">EmptyState</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/Size.html">Size</a>
              </li>
              <li class="nav-group-task">
                <a href="../Structs/Value.html">Value</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Typealiases.html">Typealiases</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Typealiases.html#/s:6Katana25AnimationPropsTransformer">AnimationPropsTransformer</a>
              </li>
              <li class="nav-group-task">
                <a href="../Typealiases.html#/s:6Katana20NodeUpdateCompletion">NodeUpdateCompletion</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Associated Types.html">Associated Types</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Associated Types.html#/s:P6Katana27NodeDescriptionWithChildren9PropsType">PropsType</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">
        <section>
          <section class="section">
            <h1>Store</h1>
              <div class="declaration">
                <div class="language">
                  <pre class="highlight"><code><span class="n">open</span> <span class="kd">class</span> <span class="kt">Store</span><span class="o">&lt;</span><span class="kt">StateType</span><span class="p">:</span> <span class="kt"><a href="../Protocols/State.html">State</a></span><span class="o">&gt;</span></code></pre>

                </div>
              </div>
            <p>The <code>Store</code> class contains and manages the state of the application and the
updates to the state itself.</p>

<p>In Katana, every relevant information in the application should be stored in the
Store&rsquo;s state. The only way to update the state is to dispatch an <code><a href="../Protocols/Action.html">Action</a></code>. At this point
the store will execute the following operations:</p>

<ul>
<li>it executes the middleware</li>
<li>it creates the new state, by invoking the <code>updateState</code> function of the action</li>
<li>it updates the state</li>
<li>it executes the side effect of the action, if implemented (see <code><a href="../Protocols/ActionWithSideEffect.html">ActionWithSideEffect</a></code>)</li>
<li>it invokes all the listeners</li>
</ul>

<p><a href='#ui-integration' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='ui-integration'>UI Integration</h4></p>

<p>You typically don&rsquo;t deal directly with the store in the UI.
Katana will update the UI automatically when the state changes. It will also allow you to
get pieces of information from the store&rsquo;s state when you need them.
See <code><a href="../Protocols/ConnectedNodeDescription.html">ConnectedNodeDescription</a></code> for more information about this topic</p>

          </section>
          <section class="section task-group-section">
            <div class="task-group">
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:vC6Katana5Store5statex"></a>
                    <a name="//apple_ref/swift/Property/state" class="dashAnchor"></a>
                    <a class="token" href="#/s:vC6Katana5Store5statex">state</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>The current state of the application</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="n">open</span> <span class="nf">fileprivate</span><span class="p">(</span><span class="k">set</span><span class="p">)</span> <span class="k">var</span> <span class="nv">state</span><span class="p">:</span> <span class="kt">StateType</span></code></pre>

                        </div>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/tree/0.7.3/Katana/Store/Store.swift#L56">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC6Katana5StorecFT_GS0_x_"></a>
                    <a name="//apple_ref/swift/Method/init()" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC6Katana5StorecFT_GS0_x_">init()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>A convenience init method. The store won&rsquo;t have middleware nor dependencies for the actions
side effects</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="n">convenience</span> <span class="kd">public</span> <span class="nf">init</span><span class="p">()</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>An instance of store</p>

                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/tree/0.7.3/Katana/Store/Store.swift#L89-L91">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC6Katana5StorecFT10middlewareGSaFTFT_PS_5State_FPS_6Action_T__FFPS2__T_FPS2__T__12dependenciesPMPS_29SideEffectDependencyContainer__GS0_x_"></a>
                    <a name="//apple_ref/swift/Method/init(middleware:dependencies:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC6Katana5StorecFT10middlewareGSaFTFT_PS_5State_FPS_6Action_T__FFPS2__T_FPS2__T__12dependenciesPMPS_29SideEffectDependencyContainer__GS0_x_">init(middleware:dependencies:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>The default init method for the Store.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="nf">init</span><span class="p">(</span><span class="nv">middleware</span><span class="p">:</span> <span class="p">[</span><span class="kt">StoreMiddleware</span><span class="p">],</span> <span class="nv">dependencies</span><span class="p">:</span> <span class="kt"><a href="../Protocols/SideEffectDependencyContainer.html">SideEffectDependencyContainer</a></span><span class="o">.</span><span class="k">Type</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>middleware</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>the middleware to trigger when an action is dispatched</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>dependencies</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>the dependencies to use in the actions side effects</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>An instance of store configured with the given properties</p>

                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/tree/0.7.3/Katana/Store/Store.swift#L100-L116">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC6Katana5Store11addListenerFFT_T_FT_T_"></a>
                    <a name="//apple_ref/swift/Method/addListener(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC6Katana5Store11addListenerFFT_T_FT_T_">addListener(_:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Adds a listener to the store. A listener is basically a closure that is invoked
every time the Store&rsquo;s state changes. The listener is always invoked in the main queue</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">addListener</span><span class="p">(</span><span class="n">_</span> <span class="nv">listener</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="kt">StoreListener</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">StoreUnsubscribe</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>listener</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>the listener closure</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>a closure that can be used to remove the listener</p>

                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/tree/0.7.3/Katana/Store/Store.swift#L125-L132">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC6Katana5Store8dispatchFPS_6Action_T_"></a>
                    <a name="//apple_ref/swift/Method/dispatch(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC6Katana5Store8dispatchFPS_6Action_T_">dispatch(_:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Dispatches an action</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">dispatch</span><span class="p">(</span><span class="n">_</span> <span class="nv">action</span><span class="p">:</span> <span class="kt"><a href="../Protocols/Action.html">Action</a></span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>action</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>the action to dispatch</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/tree/0.7.3/Katana/Store/Store.swift#L139-L144">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:vC6Katana5Store8anyStatePS_5State_"></a>
                    <a name="//apple_ref/swift/Property/anyState" class="dashAnchor"></a>
                    <a class="token" href="#/s:vC6Katana5Store8anyStatePS_5State_">anyState</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Implementation of the AnyStore protocol.</p>

<div class="aside aside-see-also">
    <p class="aside-title">See also</p>
    <code><a href="../Protocols/AnyStore.html">AnyStore</a></code>

</div>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="k">var</span> <span class="nv">anyState</span><span class="p">:</span> <span class="kt"><a href="../Protocols/State.html">State</a></span></code></pre>

                        </div>
                      </div>
                      <div class="slightly-smaller">
                        <a href="https://github.com/BendingSpoons/katana-swift/tree/0.7.3/Katana/Store/Store.swift#L233-L235">Show on GitHub</a>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
          </section>
        </section>
        <section id="footer">
          <p>&copy; 2017 <a class="link" href="http://bendingspoons.com" target="_blank" rel="external">Bending Spoons Team</a>. All rights reserved. (Last updated: 2017-03-13)</p>
          <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.4</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
        </section>
      </article>
    </div>
  </body>
</div>
</html>
