Skip to content

Commit

Permalink
Update the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Oct 27, 2023
1 parent d3380f9 commit a39da91
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/api/webstorage/Storage.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
float: none;
text-shadow: 0 0 0 transparent;
}
</style><nav class="nav"><div class="navbar"><div class="navbar-inner" style="background:#ea8220; border-bottom:1px solid rgba(0,0,0,.09)"><div class="container"><a class="brand" style="color:#000000" href="../">Web Storage for Haxe</a><a href="#" id="theme-toggle" class="brand" style="color:#000000" onclick="toggleTheme()" title="Toggle Dark Mode"><i class="fa fa-moon-o"></i></a></div></div></div></nav><div class="container main-content"><div class="row-fluid"><div class="span3"><div class="well sidebar-nav"><form class="form-search" id="searchForm"><div class="input-prepend input-block-level"><span class="add-on"><i class="fa fa-search"></i></span><input id="search" type="text" placeholder="Filter (Ctrl+P)" autocomplete="off"/></div></form></div><div class="well sidebar-nav" id="explorer"><div id="nav"></div></div></div><div class="span9"><div class="page-header"><span class="viewsource"><a href="https://github.com/cedx/webstorage.hx/blob/main/src/webstorage/Storage.hx" class="btn btn-medium"><i class="fa fa-eye"></i> View source</a></span><h1><small>class</small> Storage</h1><h4><small>package <a href="../index.html">webstorage</a></small></h4> <span class="label label-meta label-meta-jsonStringify" title="">@:jsonStringify(function(storage) -&gt; @:implicitReturn return [for (key =&gt; value in storage) key =&gt; value])</span></div><div class="body"><div class="doc doc-main"><p>Provides access to the <a href="https://developer.mozilla.org/docs/Web/API/Web_Storage_API">Web Storage</a>.</p></div><h3 class="section">Static methods</h3><div class="fields"><div class="field "><a name="local"></a><h3 class="anchor"><code><span class="label label-static">static</span><span class="label label-inline">inline</span><a href="#local"><span class="identifier">local</span></a>(<span style="white-space:nowrap">?options:<span class="type">Null</span>&lt;<a class="type" title="webstorage.StorageOptions - Defines the options of a Storage instance." href="../webstorage/StorageOptions.html">StorageOptions</a>&gt;</span>):<a class="type" title="webstorage.Storage - Provides access to the Web Storage." href="../webstorage/Storage.html">Storage</a></code></h3><div class="doc"><p>Creates a new local storage service.</p></div></div><div class="field "><a name="session"></a><h3 class="anchor"><code><span class="label label-static">static</span><span class="label label-inline">inline</span><a href="#session"><span class="identifier">session</span></a>(<span style="white-space:nowrap">?options:<span class="type">Null</span>&lt;<a class="type" title="webstorage.StorageOptions - Defines the options of a Storage instance." href="../webstorage/StorageOptions.html">StorageOptions</a>&gt;</span>):<a class="type" title="webstorage.Storage - Provides access to the Web Storage." href="../webstorage/Storage.html">Storage</a></code></h3><div class="doc"><p>Creates a new session storage service.</p></div></div></div><h3 class="section">Variables</h3><div class="fields"><div class="field "><a name="keys"></a><h3 class="anchor"><code><span class="label">read only</span><a href="#keys"><span class="identifier">keys</span></a>:<span class="type">Array</span>&lt;<span class="type">String</span>&gt;</code></h3><div class="doc"><p>The keys of this storage.</p></div></div><div class="field "><a name="length"></a><h3 class="anchor"><code><span class="label">read only</span><a href="#length"><span class="identifier">length</span></a>:<span class="type">Int</span></code></h3><div class="doc"><p>The number of entries in this storage.</p></div></div><div class="field "><a name="onChange"></a><h3 class="anchor"><code><span class="label label-final">final</span><a href="#onChange"><span class="identifier">onChange</span></a>:<span class="type">Signal</span>&lt;<a class="type" title="webstorage.StorageEvent - An event triggered when the storage has been changed." href="../webstorage/StorageEvent.html">StorageEvent</a>&gt;</code></h3><div class="doc"><p>The stream of storage events.</p></div></div></div><h3 class="section">Methods</h3><div class="fields"><div class="field "><a name="clear"></a><h3 class="anchor"><code><a href="#clear"><span class="identifier">clear</span></a>():<span class="type">Void</span></code></h3><div class="doc"><p>Removes all entries from this storage.</p></div></div><div class="field "><a name="exists"></a><h3 class="anchor"><code><a href="#exists"><span class="identifier">exists</span></a>(<span style="white-space:nowrap">key:<span class="type">String</span></span>):<span class="type">Bool</span></code></h3><div class="doc"><p>Gets a value indicating whether this storage contains the specified <code>key</code>.</p></div></div><div class="field "><a name="get"></a><h3 class="anchor"><code><a href="#get"><span class="identifier">get</span></a>(<span style="white-space:nowrap">key:<span class="type">String</span></span>):<span class="type">Option</span>&lt;<span class="type">String</span>&gt;</code></h3><div class="doc"><p>Gets the value associated with the specified <code>key</code>. Returns <code>None</code> if the <code>key</code> does not exist.</p></div></div><div class="field "><a name="getObject"></a><h3 class="anchor"><code><a href="#getObject"><span class="identifier">getObject</span></a>&lt;<span class="type">T</span>&gt;(<span style="white-space:nowrap">key:<span class="type">String</span></span>):<span class="type">Option</span>&lt;<span class="type">T</span>&gt;</code></h3><div class="doc"><p>Gets the deserialized value associated with the specified <code>key</code>.
</style><nav class="nav"><div class="navbar"><div class="navbar-inner" style="background:#ea8220; border-bottom:1px solid rgba(0,0,0,.09)"><div class="container"><a class="brand" style="color:#000000" href="../">Web Storage for Haxe</a><a href="#" id="theme-toggle" class="brand" style="color:#000000" onclick="toggleTheme()" title="Toggle Dark Mode"><i class="fa fa-moon-o"></i></a></div></div></div></nav><div class="container main-content"><div class="row-fluid"><div class="span3"><div class="well sidebar-nav"><form class="form-search" id="searchForm"><div class="input-prepend input-block-level"><span class="add-on"><i class="fa fa-search"></i></span><input id="search" type="text" placeholder="Filter (Ctrl+P)" autocomplete="off"/></div></form></div><div class="well sidebar-nav" id="explorer"><div id="nav"></div></div></div><div class="span9"><div class="page-header"><span class="viewsource"><a href="https://github.com/cedx/webstorage.hx/blob/main/src/webstorage/Storage.hx" class="btn btn-medium"><i class="fa fa-eye"></i> View source</a></span><h1><small>class</small> Storage</h1><h4><small>package <a href="../index.html">webstorage</a></small></h4> <span class="label label-meta label-meta-jsonStringify" title="">@:jsonStringify(function(storage) -&gt; @:implicitReturn return [for (key =&gt; value in storage) key =&gt; value])</span></div><div class="body"><div class="doc doc-main"><p>Provides access to the <a href="https://developer.mozilla.org/docs/Web/API/Web_Storage_API">Web Storage</a>.</p></div><h3 class="section">Static methods</h3><div class="fields"><div class="field "><a name="local"></a><h3 class="anchor"><code><span class="label label-static">static</span><span class="label label-inline">inline</span><a href="#local"><span class="identifier">local</span></a>(<span style="white-space:nowrap">?options:<span class="type">Null</span>&lt;<a class="type" title="webstorage.StorageOptions - Defines the options of a Storage instance." href="../webstorage/StorageOptions.html">StorageOptions</a>&gt;</span>):<a class="type" title="webstorage.Storage - Provides access to the Web Storage." href="../webstorage/Storage.html">Storage</a></code></h3><div class="doc"><p>Creates a new local storage service.</p></div></div><div class="field "><a name="session"></a><h3 class="anchor"><code><span class="label label-static">static</span><span class="label label-inline">inline</span><a href="#session"><span class="identifier">session</span></a>(<span style="white-space:nowrap">?options:<span class="type">Null</span>&lt;<a class="type" title="webstorage.StorageOptions - Defines the options of a Storage instance." href="../webstorage/StorageOptions.html">StorageOptions</a>&gt;</span>):<a class="type" title="webstorage.Storage - Provides access to the Web Storage." href="../webstorage/Storage.html">Storage</a></code></h3><div class="doc"><p>Creates a new session storage service.</p></div></div></div><h3 class="section">Variables</h3><div class="fields"><div class="field "><a name="keys"></a><h3 class="anchor"><code><span class="label">read only</span><a href="#keys"><span class="identifier">keys</span></a>:<span class="type">Array</span>&lt;<span class="type">String</span>&gt;</code></h3><div class="doc"><p>The keys of this storage.</p></div></div><div class="field "><a name="length"></a><h3 class="anchor"><code><span class="label">read only</span><a href="#length"><span class="identifier">length</span></a>:<span class="type">Int</span></code></h3><div class="doc"><p>The number of entries in this storage.</p></div></div><div class="field "><a name="onChange"></a><h3 class="anchor"><code><span class="label label-final">final</span><a href="#onChange"><span class="identifier">onChange</span></a>:<span class="type">Signal</span>&lt;<a class="type" title="webstorage.StorageEvent - An event triggered when the storage has been changed." href="../webstorage/StorageEvent.html">StorageEvent</a>&gt;</code></h3><div class="doc"><p>The stream of storage events.</p></div></div></div><h3 class="section">Methods</h3><div class="fields"><div class="field "><a name="clear"></a><h3 class="anchor"><code><a href="#clear"><span class="identifier">clear</span></a>():<span class="type">Void</span></code></h3><div class="doc"><p>Removes all entries from this storage.</p></div></div><div class="field "><a name="exists"></a><h3 class="anchor"><code><a href="#exists"><span class="identifier">exists</span></a>(<span style="white-space:nowrap">key:<span class="type">String</span></span>):<span class="type">Bool</span></code></h3><div class="doc"><p>Gets a value indicating whether this storage contains the specified <code>key</code>.</p></div></div><div class="field "><a name="get"></a><h3 class="anchor"><code><a href="#get"><span class="identifier">get</span></a>(<span style="white-space:nowrap">key:<span class="type">String</span></span>):<span class="type">Option</span>&lt;<span class="type">String</span>&gt;</code></h3><div class="doc"><p>Gets the value associated with the specified <code>key</code>. Returns <code>None</code> if the <code>key</code> does not exist.</p></div></div><div class="field "><a name="getObject"></a><h3 class="anchor"><code><a href="#getObject"><span class="identifier">getObject</span></a>&lt;<span class="type">Type</span>&gt;(<span style="white-space:nowrap">key:<span class="type">String</span></span>):<span class="type">Option</span>&lt;<span class="type">Type</span>&gt;</code></h3><div class="doc"><p>Gets the deserialized value associated with the specified <code>key</code>.
Returns <code>None</code> if the <code>key</code> does not exist or its value cannot be deserialized.</p></div></div><div class="field "><a name="keyValueIterator"></a><h3 class="anchor"><code><span class="label label-inline">inline</span><a href="#keyValueIterator"><span class="identifier">keyValueIterator</span></a>():<span class="type">KeyValueIterator</span>&lt;<span class="type">String</span>, <span class="type">String</span>&gt;</code></h3><div class="doc"><p>Returns a new iterator that allows iterating the entries of this storage.</p></div></div><div class="field "><a name="putIfAbsent"></a><h3 class="anchor"><code><a href="#putIfAbsent"><span class="identifier">putIfAbsent</span></a>(<span style="white-space:nowrap">key:<span class="type">String</span>,</span> <span style="white-space:nowrap">ifAbsent:()&nbsp;&#8209;&gt;&nbsp;<span class="type">String</span></span>):<span class="type">Outcome</span>&lt;<span class="type">String</span>, <span class="type">Error</span>&gt;</code></h3><div class="doc"><p>Looks up the value of the specified <code>key</code>, or add a new value if it isn't there.
Returns the value associated with <code>key</code>, if there is one.
Otherwise calls <code>ifAbsent</code> to get a new value, associates <code>key</code> with that value, and then returns the new value.</p></div></div><div class="field "><a name="putObjectIfAbsent"></a><h3 class="anchor"><code><a href="#putObjectIfAbsent"><span class="identifier">putObjectIfAbsent</span></a>&lt;<span class="type">T</span>&gt;(<span style="white-space:nowrap">key:<span class="type">String</span>,</span> <span style="white-space:nowrap">ifAbsent:()&nbsp;&#8209;&gt;&nbsp;<span class="type">T</span></span>):<span class="type">Outcome</span>&lt;<span class="type">T</span>, <span class="type">Error</span>&gt;</code></h3><div class="doc"><p>Looks up the value of the specified <code>key</code>, or add a new value if it isn't there.
Otherwise calls <code>ifAbsent</code> to get a new value, associates <code>key</code> with that value, and then returns the new value.</p></div></div><div class="field "><a name="putObjectIfAbsent"></a><h3 class="anchor"><code><a href="#putObjectIfAbsent"><span class="identifier">putObjectIfAbsent</span></a>&lt;<span class="type">Type</span>&gt;(<span style="white-space:nowrap">key:<span class="type">String</span>,</span> <span style="white-space:nowrap">ifAbsent:()&nbsp;&#8209;&gt;&nbsp;<span class="type">Type</span></span>):<span class="type">Outcome</span>&lt;<span class="type">Type</span>, <span class="type">Error</span>&gt;</code></h3><div class="doc"><p>Looks up the value of the specified <code>key</code>, or add a new value if it isn't there.
Returns the deserialized value associated with <code>key</code>, if there is one.
Otherwise calls <code>ifAbsent</code> to get a new value, serializes it and associates <code>key</code> with that value, and then returns the new value.</p></div></div><div class="field "><a name="remove"></a><h3 class="anchor"><code><a href="#remove"><span class="identifier">remove</span></a>(<span style="white-space:nowrap">key:<span class="type">String</span></span>):<span class="type">Option</span>&lt;<span class="type">String</span>&gt;</code></h3><div class="doc"><p>Removes the value associated with the specified <code>key</code>.
Returns the value associated with the <code>key</code> before it was removed.</p></div></div><div class="field "><a name="set"></a><h3 class="anchor"><code><a href="#set"><span class="identifier">set</span></a>(<span style="white-space:nowrap">key:<span class="type">String</span>,</span> <span style="white-space:nowrap">value:<span class="type">String</span></span>):<span class="type">Outcome</span>&lt;<span class="type">Noise</span>, <span class="type">Error</span>&gt;</code></h3><div class="doc"><p>Associates a given <code>value</code> with the specified <code>key</code>.</p></div></div><div class="field "><a name="setObject"></a><h3 class="anchor"><code><a href="#setObject"><span class="identifier">setObject</span></a>&lt;<span class="type">T</span>&gt;(<span style="white-space:nowrap">key:<span class="type">String</span>,</span> <span style="white-space:nowrap">value:<span class="type">T</span></span>):<span class="type">Outcome</span>&lt;<span class="type">Noise</span>, <span class="type">Error</span>&gt;</code></h3><div class="doc"><p>Serializes and associates a given <code>value</code> with the specified <code>key</code>.</p></div></div><div class="field "><a name="toJSON"></a><h3 class="anchor"><code><a href="#toJSON"><span class="identifier">toJSON</span></a>():<span class="type">Array</span>&lt;<span class="type">Array</span>&lt;<span class="type">String</span>&gt;&gt;</code></h3><div class="doc"><p>Converts this storage to a JSON representation.</p></div></div></div></div></div></div></div><footer class="section site-footer" style="background:#ea8220"><div class="container"><div class="copyright"><p style="color:#000000">This documentation is generated for version 5.2.0</p><p style="color:#000000">&copy; 2023 &nbsp;<a style="color:#000000" href="https://docs.belin.io/webstorage.hx">https://docs.belin.io/webstorage.hx</a></p></div></div></footer><script src="..//highlighter.js"></script><link href="../highlighter.css" rel="stylesheet"/></body></html>
Returns the value associated with the <code>key</code> before it was removed.</p></div></div><div class="field "><a name="set"></a><h3 class="anchor"><code><a href="#set"><span class="identifier">set</span></a>(<span style="white-space:nowrap">key:<span class="type">String</span>,</span> <span style="white-space:nowrap">value:<span class="type">String</span></span>):<span class="type">Outcome</span>&lt;<span class="type">Noise</span>, <span class="type">Error</span>&gt;</code></h3><div class="doc"><p>Associates a given <code>value</code> with the specified <code>key</code>.</p></div></div><div class="field "><a name="setObject"></a><h3 class="anchor"><code><a href="#setObject"><span class="identifier">setObject</span></a>&lt;<span class="type">Type</span>&gt;(<span style="white-space:nowrap">key:<span class="type">String</span>,</span> <span style="white-space:nowrap">value:<span class="type">Type</span></span>):<span class="type">Outcome</span>&lt;<span class="type">Noise</span>, <span class="type">Error</span>&gt;</code></h3><div class="doc"><p>Serializes and associates a given <code>value</code> with the specified <code>key</code>.</p></div></div><div class="field "><a name="toJSON"></a><h3 class="anchor"><code><a href="#toJSON"><span class="identifier">toJSON</span></a>():<span class="type">Array</span>&lt;<span class="type">Array</span>&lt;<span class="type">String</span>&gt;&gt;</code></h3><div class="doc"><p>Converts this storage to a JSON representation.</p></div></div></div></div></div></div></div><footer class="section site-footer" style="background:#ea8220"><div class="container"><div class="copyright"><p style="color:#000000">This documentation is generated for version 5.2.0</p><p style="color:#000000">&copy; 2023 &nbsp;<a style="color:#000000" href="https://docs.belin.io/webstorage.hx">https://docs.belin.io/webstorage.hx</a></p></div></div></footer><script src="..//highlighter.js"></script><link href="../highlighter.css" rel="stylesheet"/></body></html>
6 changes: 3 additions & 3 deletions src/webstorage/Storage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Storage {
Gets the deserialized value associated with the specified `key`.
Returns `None` if the `key` does not exist or its value cannot be deserialized.
**/
public function getObject<T>(key: String): Option<T> {
public function getObject<Type>(key: String): Option<Type> {
final value = backend.getItem(buildKey(key));
return value == null ? None : switch Error.catchExceptions(() -> Json.parse(value)) {
case Failure(_): None;
Expand All @@ -109,7 +109,7 @@ class Storage {
Returns the deserialized value associated with `key`, if there is one.
Otherwise calls `ifAbsent` to get a new value, serializes it and associates `key` with that value, and then returns the new value.
**/
public function putObjectIfAbsent<T>(key: String, ifAbsent: () -> T): Outcome<T, Error>
public function putObjectIfAbsent<Type>(key: String, ifAbsent: () -> Type): Outcome<Type, Error>
return switch getObject(key) {
case Some(value): Success(value);
case None: final value = ifAbsent(); setObject(key, value).map(_ -> value);
Expand All @@ -136,7 +136,7 @@ class Storage {
}, exception -> Error.withData(InsufficientStorage, "The storage is full.", exception));

/** Serializes and associates a given `value` with the specified `key`. **/
public function setObject<T>(key: String, value: T): Outcome<Noise, Error>
public function setObject<Type>(key: String, value: Type): Outcome<Noise, Error>
return switch Error.catchExceptions(() -> Json.stringify(value)) {
case Failure(_): Failure(new Error(UnprocessableEntity, "Unable to encode the specified value in JSON."));
case Success(json): set(key, json);
Expand Down

0 comments on commit a39da91

Please sign in to comment.