packages feed

happs-tutorial-0.8.1: templates/yourfirstmacid.st

<h3>Your first applications with Happstack.State</h3>
<p>Now we're getting into the very basics of how to make an application with Happstack.State.</p>
<p>Take a look at the application defined in <a href="/src/FirstMacid.hs">FirstMacid.hs</a>, read
the comments, and copy it somewhere you feel comfortable running it.</p>
<p>Play with it at the command prompt for a bit.  Choose various values to add to the state.
Close the program, and then reload it.  Check the state and everything should be saved right where
you left it.  Cool, eh?</p>
<p>One thing I want to point out is that this example makes no use of Happstack.Server whatsoever.
They are completely independent of each other.</p>
<p>Now here's a second example to look at, one that demonstrates using a non-trivial Dependencies
list in order to improve modularity:  <a href="/src/ComponentExample.hs">ComponentExample.hs</a>.  
Again, you'll want to read the inline comments as they contain the bulk of the instruction of this chapter.</p>
<p>To summarize the major points of this chapter:  </p>
<ul>
<li>By default, Happstack.State serializes an event record under the _local directory.</li>
<li>The state management is started with the startSystemState function</li>
<li>For a data type to be used as the state, it needs to be an instance of Component which itself
requires a number of other instances.</li>
<li>Checkpointing allows you to serialize the actual state and not just the event record.  
    <ul>
      <li>You can roll back time by deleting the events that took place after the checkpoint.</li>
      <li>Checkpointing must be done by manually calling createCheckpoint</li>
    </ul></li>
<li>Dependencies allow separate components to be combined together into the final top level state.</li>
</ul> 
<p>Next we'll talk about creating 
<a href="/tutorial/multimaster">distributed</a> applications using Happstack.State.</p>