Skip to content

Commit

Permalink
feat: feat: add options.validator, getValidator, setValidator
Browse files Browse the repository at this point in the history
`Atom.of` now takes an optional `options` dictionary, which accepts a `validator` predicate function
that will validate Atom state at initialization, `swap`, and `set`. `validator` is `() => true` by
default. An atom's validator function can be also be set after initialization with `setValidator`.
And atom's validator can be accessed with `getValidator`.
  • Loading branch information
derrickbeining committed Dec 11, 2018
1 parent 80e2dfc commit 39bf743
Show file tree
Hide file tree
Showing 16 changed files with 683 additions and 84 deletions.
2 changes: 1 addition & 1 deletion docs/assets/js/search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 18 additions & 10 deletions docs/classes/atom.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,11 @@ <h1>Class Atom&lt;S&gt;</h1>
<section class="tsd-panel tsd-comment">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p><code>@libre/atom</code> provides a data type called <code>Atom</code> and a few functions for working with <code>Atom</code>s.
It is heavily inspired by <code>atom</code>s in Clojure(Script).</p>
<p>A data structure useful for providing a controlled, predictable mechanism for mutability.
Allows multiple components of a program to share read/write access to some state in such
a way that no component can mutate another component&#39;s current reference to the state in
the middle of some process or asynchronous operation.</p>
</div>
<p>Atoms provide a predictable way to manage state that is shared by multiple components of a
program as that state changes over time. They are particularly useful in the functional and reactive
programming paradigms, where most components of a program are pure functions operating on
immutable data. In this context, Atoms provide a form of mutability that is controlled in such
a way that no component can mutate another component&#39;s current reference to the state in
the middle of some process or asynchronous operation.</p>
</div>
</section>
<section class="tsd-panel tsd-type-parameters">
Expand Down Expand Up @@ -111,13 +107,13 @@ <h2>Methods</h2>
<a name="of" class="tsd-anchor"></a>
<h3><span class="tsd-flag ts-flagStatic">Static</span> of</h3>
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-static">
<li class="tsd-signature tsd-kind-icon">of&lt;S&gt;<span class="tsd-signature-symbol">(</span>state<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="atom.html" class="tsd-signature-type">Atom</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">&gt;</span></li>
<li class="tsd-signature tsd-kind-icon">of&lt;S&gt;<span class="tsd-signature-symbol">(</span>state<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">S</span>, options<span class="tsd-signature-symbol">?: </span><a href="../interfaces/atomconstructoroptions.html" class="tsd-signature-type">AtomConstructorOptions</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="atom.html" class="tsd-signature-type">Atom</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">&gt;</span></li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in atom.ts:53</li>
<li>Defined in atom.ts:50</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -150,6 +146,9 @@ <h4 class="tsd-parameters-title">Parameters</h4>
<li>
<h5>state: <span class="tsd-signature-type">S</span></h5>
</li>
<li>
<h5><span class="tsd-flag ts-flagOptional">Optional</span> options: <a href="../interfaces/atomconstructoroptions.html" class="tsd-signature-type">AtomConstructorOptions</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">&gt;</span></h5>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <a href="atom.html" class="tsd-signature-type">Atom</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">&gt;</span></h4>
</li>
Expand Down Expand Up @@ -179,6 +178,9 @@ <h4 class="tsd-returns-title">Returns <a href="atom.html" class="tsd-signature-t
</li>
</ul>
<ul class="after-current">
<li class=" tsd-kind-interface tsd-has-type-parameter">
<a href="../interfaces/atomconstructoroptions.html" class="tsd-kind-icon">Atom<wbr>Constructor<wbr>Options</a>
</li>
<li class=" tsd-kind-type-alias tsd-has-type-parameter">
<a href="../globals.html#atomstate" class="tsd-kind-icon">Atom<wbr>State</a>
</li>
Expand All @@ -188,9 +190,15 @@ <h4 class="tsd-returns-title">Returns <a href="atom.html" class="tsd-signature-t
<li class=" tsd-kind-function tsd-has-type-parameter">
<a href="../globals.html#deref" class="tsd-kind-icon">deref</a>
</li>
<li class=" tsd-kind-function tsd-has-type-parameter">
<a href="../globals.html#getvalidator" class="tsd-kind-icon">get<wbr>Validator</a>
</li>
<li class=" tsd-kind-function tsd-has-type-parameter">
<a href="../globals.html#set" class="tsd-kind-icon">set</a>
</li>
<li class=" tsd-kind-function tsd-has-type-parameter">
<a href="../globals.html#setvalidator" class="tsd-kind-icon">set<wbr>Validator</a>
</li>
<li class=" tsd-kind-function tsd-has-type-parameter">
<a href="../globals.html#swap" class="tsd-kind-icon">swap</a>
</li>
Expand Down
Loading

0 comments on commit 39bf743

Please sign in to comment.