forerunnerdb
Version:
A NoSQL document store database for browsers and Node.js.
1,954 lines (483 loc) • 23.5 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: Persist</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: Persist</h1>
<section>
<header>
<h2>
Persist
</h2>
</header>
<article>
<div class="container-overview">
<h4 class="name" id="Persist"><span class="type-signature"></span>new Persist<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
The persistent storage class handles loading and saving data to browser
storage.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line25">line 25</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="addStep"><span class="type-signature"></span>addStep<span class="type-signature"></span></h4>
<div class="description">
Adds an encode/decode step to the persistent storage system so
that you can add custom functionality.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line169">line 169</a>
</li></ul></dd>
</dl>
<h4 class="name" id="localforage"><span class="type-signature"></span>localforage<span class="type-signature"></span></h4>
<div class="description">
The local forage library.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line32">line 32</a>
</li></ul></dd>
</dl>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="_decode"><span class="type-signature">(private) </span>_decode<span class="signature">(val, meta, finished)</span><span class="type-signature"></span></h4>
<div class="description">
Takes encoded data and decodes it for use as JS native objects and arrays.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>val</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">The currently encoded string data.</td>
</tr>
<tr>
<td class="name"><code>meta</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">Meta data object that can be used to pass back useful
supplementary data.</td>
</tr>
<tr>
<td class="name"><code>finished</code></td>
<td class="type">
<span class="param-type"><a href="global.html#function">function</a></span>
</td>
<td class="description last">The callback method to call when decoding is
completed.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line222">line 222</a>
</li></ul></dd>
</dl>
<h4 class="name" id="_encode"><span class="type-signature">(private) </span>_encode<span class="signature">(val, meta, finished)</span><span class="type-signature"></span></h4>
<div class="description">
Takes native JS data and encodes it for for storage as a string.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>val</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">The current un-encoded data.</td>
</tr>
<tr>
<td class="name"><code>meta</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">Meta data object that can be used to pass back useful
supplementary data.</td>
</tr>
<tr>
<td class="name"><code>finished</code></td>
<td class="type">
<span class="param-type"><a href="global.html#function">function</a></span>
</td>
<td class="description last">The callback method to call when encoding is
completed.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line271">line 271</a>
</li></ul></dd>
</dl>
<h4 class="name" id="decode"><span class="type-signature"></span>decode<span class="signature">(val, finished)</span><span class="type-signature"></span></h4>
<div class="description">
Starts a decode waterfall process.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>val</code></td>
<td class="type">
<span class="param-type">*</span>
</td>
<td class="description last">The data to be decoded.</td>
</tr>
<tr>
<td class="name"><code>finished</code></td>
<td class="type">
<span class="param-type"><a href="global.html#function">function</a></span>
</td>
<td class="description last">The callback to pass final data to.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line131">line 131</a>
</li></ul></dd>
</dl>
<h4 class="name" id="driver"><span class="type-signature"></span>driver<span class="signature">(val)</span><span class="type-signature"> → {*}</span></h4>
<div class="description">
Gets / sets the driver used when persisting data.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>val</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">Specify the driver type (LOCALSTORAGE,
WEBSQL or INDEXEDDB)</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line101">line 101</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">*</span>
</dd>
</dl>
<h4 class="name" id="drop"><span class="type-signature"></span>drop<span class="signature">(key, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
Deletes data in persistent storage stored under the passed key.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>key</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="attributes">
</td>
<td class="description last">The key to drop data for in the storage.</td>
</tr>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type"><a href="global.html#function">function</a></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">The method to call when the data is dropped.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line349">line 349</a>
</li></ul></dd>
</dl>
<h4 class="name" id="encode"><span class="type-signature"></span>encode<span class="signature">(val, finished)</span><span class="type-signature"></span></h4>
<div class="description">
Starts an encode waterfall process.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>val</code></td>
<td class="type">
<span class="param-type">*</span>
</td>
<td class="description last">The data to be encoded.</td>
</tr>
<tr>
<td class="name"><code>finished</code></td>
<td class="type">
<span class="param-type"><a href="global.html#function">function</a></span>
</td>
<td class="description last">The callback to pass final data to.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line142">line 142</a>
</li></ul></dd>
</dl>
<h4 class="name" id="init"><span class="type-signature"></span>init<span class="signature">(db)</span><span class="type-signature"></span></h4>
<div class="description">
The init method that can be overridden or extended.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>db</code></td>
<td class="type">
<span class="param-type"><a href="Db.html">Db</a></span>
</td>
<td class="description last">The ForerunnerDB database instance.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line38">line 38</a>
</li></ul></dd>
</dl>
<h4 class="name" id="load"><span class="type-signature"></span>load<span class="signature">(key, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
Loads and decodes data from the passed key.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>key</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="attributes">
</td>
<td class="description last">The key to retrieve data from in the persistent
storage.</td>
</tr>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type"><a href="global.html#function">function</a></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">The method to call when the load process
has completed.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line326">line 326</a>
</li></ul></dd>
</dl>
<h4 class="name" id="mode"><span class="type-signature"></span>mode<span class="signature">(type)</span><span class="type-signature"> → {*}</span></h4>
<div class="description">
Gets / sets the persistent storage mode (the library used
to persist data to the browser - defaults to localForage).
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>type</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last">The library to use for storage. Defaults
to localForage.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line86">line 86</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">*</span>
</dd>
</dl>
<h4 class="name" id="save"><span class="type-signature"></span>save<span class="signature">(key, data, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
Encodes passed data and then stores it in the browser's persistent
storage layer.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>key</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="attributes">
</td>
<td class="description last">The key to store the data under in the persistent
storage.</td>
</tr>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
</td>
<td class="description last">The data to store under the key.</td>
</tr>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type"><a href="global.html#function">function</a></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">The method to call when the save process
has completed.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line301">line 301</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="ActiveBucket.html">ActiveBucket</a></li><li><a href="Angular.html">Angular</a></li><li><a href="AutoBind.html">AutoBind</a></li><li><a href="BinaryTree.html">BinaryTree</a></li><li><a href="Collection.html">Collection</a></li><li><a href="CollectionGroup.html">CollectionGroup</a></li><li><a href="Core.html">Core</a></li><li><a href="Db.html">Db</a></li><li><a href="Document.html">Document</a></li><li><a href="Grid.html">Grid</a></li><li><a href="Highchart.html">Highchart</a></li><li><a href="IndexBinaryTree.html">IndexBinaryTree</a></li><li><a href="IndexHashMap.html">IndexHashMap</a></li><li><a href="Infinilist.html">Infinilist</a></li><li><a href="KeyValueStore.html">KeyValueStore</a></li><li><a href="Metrics.html">Metrics</a></li><li><a href="OldView.html">OldView</a></li><li><a href="Operation.html">Operation</a></li><li><a href="Overload.html">Overload</a></li><li><a href="Path.html">Path</a></li><li><a href="Persist.html">Persist</a></li><li><a href="ReactorIO.html">ReactorIO</a></li><li><a href="Serialiser.html">Serialiser</a></li><li><a href="Shared.overload.html">overload</a></li><li><a href="View.html">View</a></li></ul><h3>Mixins</h3><ul><li><a href="ChainReactor.html">ChainReactor</a></li><li><a href="crcTable.html">crcTable</a></li><li><a href="Shared.html">Shared</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%2522boolean,function%2522">"boolean, function"</a></li><li><a href="global.html#%2522string,*,function%2522">"string, *, function"</a></li><li><a href="global.html#%2522string,function%2522">"string, function"</a></li><li><a href="global.html#boolean">boolean</a></li><li><a href="global.html#function">function</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.3</a> on Thu Nov 19 2015 13:31:32 GMT+0000 (GMT)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>