Skip to content

Commit

Permalink
Merge pull request #82 from EOSIO/develop
Browse files Browse the repository at this point in the history
Release 3.1.0
  • Loading branch information
jeffreyssmith2nd authored Nov 26, 2018
2 parents fc3ca3a + 52486bf commit 63f6a09
Show file tree
Hide file tree
Showing 32 changed files with 3,253 additions and 1,112 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ before_install:
- npm install -g typescript
script:
- npm run lint
- npm run test

58 changes: 19 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,6 @@ There are other solutions to the above problems that involve legacy persistence
1. Actions run their corresponding Effects, triggering external events
1. Client queries API for updated data

## Usage

This library provides the following classes:

* [**`AbstractActionReader`**](https://eosio.github.io/demux-js/classes/abstractactionreader.html): Abstract class used for implementing your own Action Readers

* [**`AbstractActionHandler`**](https://eosio.github.io/demux-js/classes/abstractactionhandler.html): Abstract class used for implementing your own Action Handlers

* [**`BaseActionWatcher`**](https://eosio.github.io/demux-js/classes/baseactionwatcher.html): Base class that implements a ready-to-use Action Watcher

#### [**View full API documentation here.**](https://eosio.github.io/demux-js/)

## Class Implementations

Expand All @@ -82,40 +71,31 @@ Repository | Description
To get your project listed, add it here and submit a PR!


## Example
## Usage

```js
// Let's read from an EOS node
const { NodeosActionReader } = require("demux-eos")

// Assuming you've created your own subclass of AbstractActionHandler
const MyActionHandler = require("./MyActionHandler")

// Ties everything together in a polling loop
const { BaseActionWatcher } = require("demux")
This library provides the following classes:

// Import Updaters and Effects, which are arrays of objects:
// [ { actionType: string, (updater|effect): function }, ... ]
const updaters = require("./updaters")
const effects = require("./effects")
* [**`AbstractActionReader`**](https://eosio.github.io/demux-js/classes/abstractactionreader.html): Abstract class used for implementing your own Action Readers

const actionReader = new NodeosActionReader(
"http://some-nodeos-endpoint:8888", // Locally hosted node needed for reasonable indexing speed
12345678, // First actions relevant to this dapp happen at this block
)
* [**`AbstractActionHandler`**](https://eosio.github.io/demux-js/classes/abstractactionhandler.html): Abstract class used for implementing your own Action Handlers

const actionHandler = new MyActionHandler(
updaters,
effects,
)
* [**`BaseActionWatcher`**](https://eosio.github.io/demux-js/classes/baseactionwatcher.html): Base class that implements a ready-to-use Action Watcher

const actionWatcher = new BaseActionWatcher(
actionReader,
actionHandler,
250, // Poll at twice the block interval for less latency
)
In order to process actions, we need the following things:

actionWatcher.watch() // Start watch loop
```
- An implementation of an `AbstractActionReader`
- An implementation of an `AbstractActionHandler`
- At least one `HandlerVersion`, which contain `Updater` and `Effect` arrays

After we have these things, we need to:

- Instantiate the implemented `AbstractActionHandler`, passing in the `HandlerVersion` and any other needed configuration
- Instantiate the implemented `AbstractActionReader` with any needed configuration
- Instantiate a `BaseActionWatcher`, passing in the above Handler and Reader instances
- Call `watch()` on the Watcher

### [**API documentation**](https://eosio.github.io/demux-js/)

For more complete examples, [see the examples directory](examples/).
### [Learn from a full example](examples/eos-transfers)
2 changes: 1 addition & 1 deletion docs/assets/js/search.js

Large diffs are not rendered by default.

361 changes: 191 additions & 170 deletions docs/classes/abstractactionhandler.html

Large diffs are not rendered by default.

220 changes: 116 additions & 104 deletions docs/classes/abstractactionreader.html

Large diffs are not rendered by default.

123 changes: 100 additions & 23 deletions docs/classes/baseactionwatcher.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>BaseActionWatcher | demux-js</title>
<title>BaseActionWatcher | demux</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">/*! normalize.css v1.1.3 | MIT License | git.io/normalize */
Expand Down Expand Up @@ -879,7 +879,7 @@
<div class="container">
<div class="table-wrap">
<div class="table-cell">
<strong><a href="../index.html">demux-js</a></strong>
<strong><a href="../index.html">demux</a></strong>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
Expand Down Expand Up @@ -928,17 +928,23 @@
<li class=" tsd-kind-property tsd-parent-kind-class tsd-is-protected">
<a href="baseactionwatcher.html#pollinterval" class="tsd-kind-icon">poll<wbr>Interval</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-class tsd-is-protected">
<a href="baseactionwatcher.html#checkforblocks" class="tsd-kind-icon">check<wbr>For<wbr>Blocks</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-class">
<a href="baseactionwatcher.html#replay" class="tsd-kind-icon">replay</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-class tsd-is-protected">
<li class=" tsd-kind-method tsd-parent-kind-class">
<a href="baseactionwatcher.html#watch" class="tsd-kind-icon">watch</a>
</li>
</ul>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/action.html" class="tsd-kind-icon">Action</a>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/actionlistener.html" class="tsd-kind-icon">Action<wbr>Listener</a>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/block.html" class="tsd-kind-icon">Block</a>
</li>
Expand All @@ -948,22 +954,29 @@
<li class=" tsd-kind-interface">
<a href="../interfaces/effect.html" class="tsd-kind-icon">Effect</a>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/handlerversion.html" class="tsd-kind-icon">Handler<wbr>Version</a>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/indexstate.html" class="tsd-kind-icon">Index<wbr>State</a>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/updater.html" class="tsd-kind-icon">Updater</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../index.html#actioncallback" class="tsd-kind-icon">Action<wbr>Callback</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../index.html#statelessactioncallback" class="tsd-kind-icon">Stateless<wbr>Action<wbr>Callback</a>
</li>
</ul>
</nav>
<div class="container container-main">
<div class="content-wrap">
<section class="tsd-panel tsd-comment">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Cooredinates implementations of <code>AbstractActionReader</code>s and <code>AbstractActionHandler</code>s in
a polling loop.
Cooredinates implementations of <code>AbstractActionReader</code>s and <code>AbstractActionHandler</code>s in
<p>Coordinates implementations of <code>AbstractActionReader</code>s and <code>AbstractActionHandler</code>s in
a polling loop.</p>
</div>
</div>
Expand Down Expand Up @@ -997,8 +1010,9 @@ <h3>Properties</h3>
<section class="tsd-index-section ">
<h3>Methods</h3>
<ul class="tsd-index-list">
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-protected"><a href="baseactionwatcher.html#checkforblocks" class="tsd-kind-icon">check<wbr>For<wbr>Blocks</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="baseactionwatcher.html#replay" class="tsd-kind-icon">replay</a></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-protected"><a href="baseactionwatcher.html#watch" class="tsd-kind-icon">watch</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="baseactionwatcher.html#watch" class="tsd-kind-icon">watch</a></li>
</ul>
</section>
</div>
Expand All @@ -1016,19 +1030,36 @@ <h3>constructor</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in dist/BaseActionWatcher.d.ts:10</li>
<li>Defined in <a href="https://github.com/EOSIO/demux/blob/c63be46/src/BaseActionWatcher.ts#L8">src/BaseActionWatcher.ts:8</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>actionReader: <a href="abstractactionreader.html" class="tsd-signature-type">AbstractActionReader</a></h5>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>An instance of an implemented <code>AbstractActionReader</code></p>
</div>
</div>
</li>
<li>
<h5>actionHandler: <a href="abstractactionhandler.html" class="tsd-signature-type">AbstractActionHandler</a></h5>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>An instance of an implemented <code>AbstractActionHandler</code></p>
</div>
</div>
</li>
<li>
<h5>pollInterval: <span class="tsd-signature-type">number</span></h5>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Number of milliseconds between each polling loop iteration</p>
</div>
</div>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <a href="baseactionwatcher.html" class="tsd-signature-type">BaseActionWatcher</a></h4>
Expand All @@ -1041,39 +1072,79 @@ <h2>Properties</h2>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-protected">
<a name="actionhandler" class="tsd-anchor"></a>
<h3><span class="tsd-flag ts-flagProtected">Protected</span> action<wbr>Handler</h3>
<div class="tsd-signature tsd-kind-icon">action<wbr>Handler<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">AbstractActionHandler</span></div>
<div class="tsd-signature tsd-kind-icon">action<wbr>Handler<span class="tsd-signature-symbol">:</span> <a href="abstractactionhandler.html" class="tsd-signature-type">AbstractActionHandler</a></div>
<aside class="tsd-sources">
<ul>
<li>Defined in dist/BaseActionWatcher.d.ts:9</li>
<li>Defined in <a href="https://github.com/EOSIO/demux/blob/02729b2/src/BaseActionWatcher.ts#L11">src/BaseActionWatcher.ts:11</a></li>
<li>Defined in <a href="https://github.com/EOSIO/demux/blob/c63be46/src/BaseActionWatcher.ts#L16">src/BaseActionWatcher.ts:16</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>An instance of an implemented <code>AbstractActionHandler</code></p>
</div>
</div>
</section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-protected">
<a name="actionreader" class="tsd-anchor"></a>
<h3><span class="tsd-flag ts-flagProtected">Protected</span> action<wbr>Reader</h3>
<div class="tsd-signature tsd-kind-icon">action<wbr>Reader<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">AbstractActionReader</span></div>
<div class="tsd-signature tsd-kind-icon">action<wbr>Reader<span class="tsd-signature-symbol">:</span> <a href="abstractactionreader.html" class="tsd-signature-type">AbstractActionReader</a></div>
<aside class="tsd-sources">
<ul>
<li>Defined in dist/BaseActionWatcher.d.ts:8</li>
<li>Defined in <a href="https://github.com/EOSIO/demux/blob/02729b2/src/BaseActionWatcher.ts#L10">src/BaseActionWatcher.ts:10</a></li>
<li>Defined in <a href="https://github.com/EOSIO/demux/blob/c63be46/src/BaseActionWatcher.ts#L15">src/BaseActionWatcher.ts:15</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>An instance of an implemented <code>AbstractActionReader</code></p>
</div>
</div>
</section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-protected">
<a name="pollinterval" class="tsd-anchor"></a>
<h3><span class="tsd-flag ts-flagProtected">Protected</span> poll<wbr>Interval</h3>
<div class="tsd-signature tsd-kind-icon">poll<wbr>Interval<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in dist/BaseActionWatcher.d.ts:10</li>
<li>Defined in <a href="https://github.com/EOSIO/demux/blob/02729b2/src/BaseActionWatcher.ts#L12">src/BaseActionWatcher.ts:12</a></li>
<li>Defined in <a href="https://github.com/EOSIO/demux/blob/c63be46/src/BaseActionWatcher.ts#L17">src/BaseActionWatcher.ts:17</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Number of milliseconds between each polling loop iteration</p>
</div>
</div>
</section>
</section>
<section class="tsd-panel-group tsd-member-group ">
<h2>Methods</h2>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-protected">
<a name="checkforblocks" class="tsd-anchor"></a>
<h3><span class="tsd-flag ts-flagProtected">Protected</span> check<wbr>For<wbr>Blocks</h3>
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-protected">
<li class="tsd-signature tsd-kind-icon">check<wbr>For<wbr>Blocks<span class="tsd-signature-symbol">(</span>isReplay<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</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 <a href="https://github.com/EOSIO/demux/blob/c63be46/src/BaseActionWatcher.ts#L48">src/BaseActionWatcher.ts:48</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Use the actionReader and actionHandler to process new blocks.</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5><span class="tsd-flag ts-flagDefault value">Default value</span> isReplay: <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol"> =&nbsp;false</span></h5>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></h4>
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class">
<a name="replay" class="tsd-anchor"></a>
<h3>replay</h3>
Expand All @@ -1084,7 +1155,7 @@ <h3>replay</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in dist/BaseActionWatcher.d.ts:15</li>
<li>Defined in <a href="https://github.com/EOSIO/demux/blob/c63be46/src/BaseActionWatcher.ts#L23">src/BaseActionWatcher.ts:23</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -1096,24 +1167,30 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-protected">
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class">
<a name="watch" class="tsd-anchor"></a>
<h3><span class="tsd-flag ts-flagProtected">Protected</span> watch</h3>
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-protected">
<li class="tsd-signature tsd-kind-icon">watch<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></li>
<h3>watch</h3>
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class">
<li class="tsd-signature tsd-kind-icon">watch<span class="tsd-signature-symbol">(</span>isReplay<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</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 dist/BaseActionWatcher.d.ts:19</li>
<li>Defined in <a href="https://github.com/EOSIO/demux/blob/c63be46/src/BaseActionWatcher.ts#L30">src/BaseActionWatcher.ts:30</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Uses the given actionReader and actionHandler to poll and process new blocks.</p>
<p>Start a polling loop</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5><span class="tsd-flag ts-flagDefault value">Default value</span> isReplay: <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol"> =&nbsp;false</span></h5>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></h4>
</li>
</ul>
Expand Down
Loading

0 comments on commit 63f6a09

Please sign in to comment.