Skip to content

Commit

Permalink
Fixed #58
Browse files Browse the repository at this point in the history
  • Loading branch information
calebsander committed Dec 24, 2017
1 parent 106fc3c commit f9b7468
Show file tree
Hide file tree
Showing 66 changed files with 2,086 additions and 1,514 deletions.
2 changes: 1 addition & 1 deletion compiled/download.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion compiled/upload-download.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion compiled/upload.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/appendable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default abstract class AppendableBuffer {
* .pause()
* .add(4).add(5).add(6)
* .reset() //cancels [4, 5, 6]
* .resume()
* .resume() //resumes []
* .resume() //resumes [1, 2, 3]
* console.log(new Uint8Array(gb.toBuffer())) //Uint8Array [ 1, 2, 3 ]
* ````
Expand Down
12 changes: 12 additions & 0 deletions dist/recursive-registry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ import { RegisterableType, TypeAndName } from './recursive-registry-type';
* If you need to use a different type, wrap it
* in a single-field [[StructType]].
*
* THIS METHOD OF REGISTERING RECURSIVE TYPES HAS BEEN DEPRECATED.
* Instead, please use [[RecursiveType.setType]]:
* ````javascript
* //A binary tree of unsigned bytes
* let treeType = new sb.RecursiveType('tree-node')
* treeType.setType(new sb.StructType({
* left: new sb.OptionalType(treeType),
* value: new sb.UnsignedByteType,
* right: new sb.OptionalType(treeType)
* }))
* ````
*
* Example:
* ````javascript
* //A binary tree of unsigned bytes
Expand Down
12 changes: 12 additions & 0 deletions dist/recursive-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ const registeredTypes = new Map();
* If you need to use a different type, wrap it
* in a single-field [[StructType]].
*
* THIS METHOD OF REGISTERING RECURSIVE TYPES HAS BEEN DEPRECATED.
* Instead, please use [[RecursiveType.setType]]:
* ````javascript
* //A binary tree of unsigned bytes
* let treeType = new sb.RecursiveType('tree-node')
* treeType.setType(new sb.StructType({
* left: new sb.OptionalType(treeType),
* value: new sb.UnsignedByteType,
* right: new sb.OptionalType(treeType)
* }))
* ````
*
* Example:
* ````javascript
* //A binary tree of unsigned bytes
Expand Down
25 changes: 25 additions & 0 deletions dist/types/recursive.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,29 @@ export default class RecursiveType<E, READ_E extends E = E> extends AbsoluteType
writeValue(buffer: AppendableBuffer, value: E): void;
consumeValue(buffer: ArrayBuffer, offset: number): ReadResult<READ_E>;
equals(otherType: any): boolean;
/**
* An alternative to [[registerType]],
* to avoid writing the type's name twice.
* Please use this instead of [[registerType]].
*
* So this
* ````javascript
* let type = new sb.RecursiveType('abc')
* sb.registerType({
* type: new sb.StructType({
* //...
* }),
* name: 'abc'
* })
* ````
* becomes
* ````javascript
* let type = new sb.RecursiveType('abc')
* type.setType(new sb.StructType({
* //...
* }))
* ````
* @param type The type to register
*/
setType(type: RegisterableType): void;
}
27 changes: 27 additions & 0 deletions dist/types/recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,32 @@ class RecursiveType extends absolute_1.default {
return super.equals(otherType)
&& this.name === otherType.name;
}
/**
* An alternative to [[registerType]],
* to avoid writing the type's name twice.
* Please use this instead of [[registerType]].
*
* So this
* ````javascript
* let type = new sb.RecursiveType('abc')
* sb.registerType({
* type: new sb.StructType({
* //...
* }),
* name: 'abc'
* })
* ````
* becomes
* ````javascript
* let type = new sb.RecursiveType('abc')
* type.setType(new sb.StructType({
* //...
* }))
* ````
* @param type The type to register
*/
setType(type) {
recursiveRegistry.registerType({ type, name: this.name });
}
}
exports.default = RecursiveType;
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<a href="_lib_appendable_.appendablebuffer.html">AppendableBuffer</a>
</li>
</ul>
<h1>Interface AppendableBuffer</h1>
<h1>Class AppendableBuffer</h1>
</div>
</div>
</header>
Expand All @@ -74,8 +74,8 @@ <h1>Interface AppendableBuffer</h1>
<div class="lead">
<p>A &quot;writable&quot; interface, sufficient
to be able to write type and value bytes.
Implemented by <a href="../classes/_lib_growable_buffer_.growablebuffer.html">GrowableBuffer</a>, as well as
<a href="../classes/_lib_appendable_stream_.appendablestream.html">AppendableStream</a> (a wrapper around a writable stream).
Implemented by <a href="_lib_growable_buffer_.growablebuffer.html">GrowableBuffer</a>, as well as
<a href="_lib_appendable_stream_.appendablestream.html">AppendableStream</a> (a wrapper around a writable stream).
All methods can be chained, e.g.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> gb = <span class="hljs-keyword">new</span> GrowableBuffer
gb
Expand All @@ -95,42 +95,43 @@ <h3>Hierarchy</h3>
<ul class="tsd-hierarchy">
<li>
<span class="target">AppendableBuffer</span>
<ul class="tsd-hierarchy">
<li>
<a href="_lib_growable_buffer_.growablebuffer.html" class="tsd-signature-type">GrowableBuffer</a>
</li>
<li>
<a href="_lib_appendable_stream_.appendablestream.html" class="tsd-signature-type">AppendableStream</a>
</li>
</ul>
</li>
</ul>
</section>
<section class="tsd-panel">
<h3>Implemented by</h3>
<ul class="tsd-hierarchy">
<li><a href="../classes/_lib_appendable_stream_.appendablestream.html" class="tsd-signature-type">AppendableStream</a></li>
<li><a href="../classes/_lib_growable_buffer_.growablebuffer.html" class="tsd-signature-type">GrowableBuffer</a></li>
</ul>
</section>
<section class="tsd-panel-group tsd-index-group">
<h2>Index</h2>
<section class="tsd-panel tsd-index-panel">
<div class="tsd-index-content">
<section class="tsd-index-section tsd-is-external">
<h3>Properties</h3>
<ul class="tsd-index-list">
<li class="tsd-kind-property tsd-parent-kind-interface tsd-is-external"><a href="_lib_appendable_.appendablebuffer.html#length" class="tsd-kind-icon">length</a></li>
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-external"><a href="_lib_appendable_.appendablebuffer.html#length" class="tsd-kind-icon">length</a></li>
</ul>
</section>
<section class="tsd-index-section tsd-is-external">
<h3>Methods</h3>
<ul class="tsd-index-list">
<li class="tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a href="_lib_appendable_.appendablebuffer.html#add" class="tsd-kind-icon">add</a></li>
<li class="tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a href="_lib_appendable_.appendablebuffer.html#addall" class="tsd-kind-icon">add<wbr>All</a></li>
<li class="tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a href="_lib_appendable_.appendablebuffer.html#pause" class="tsd-kind-icon">pause</a></li>
<li class="tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a href="_lib_appendable_.appendablebuffer.html#reset" class="tsd-kind-icon">reset</a></li>
<li class="tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a href="_lib_appendable_.appendablebuffer.html#resume" class="tsd-kind-icon">resume</a></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="_lib_appendable_.appendablebuffer.html#add" class="tsd-kind-icon">add</a></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="_lib_appendable_.appendablebuffer.html#addall" class="tsd-kind-icon">add<wbr>All</a></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="_lib_appendable_.appendablebuffer.html#pause" class="tsd-kind-icon">pause</a></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="_lib_appendable_.appendablebuffer.html#reset" class="tsd-kind-icon">reset</a></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="_lib_appendable_.appendablebuffer.html#resume" class="tsd-kind-icon">resume</a></li>
</ul>
</section>
</div>
</section>
</section>
<section class="tsd-panel-group tsd-member-group tsd-is-external">
<h2>Properties</h2>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface tsd-is-external">
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-external">
<a name="length" class="tsd-anchor"></a>
<h3>length</h3>
<div class="tsd-signature tsd-kind-icon">length<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
Expand All @@ -148,10 +149,10 @@ <h3>length</h3>
</section>
<section class="tsd-panel-group tsd-member-group tsd-is-external">
<h2>Methods</h2>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface tsd-is-external">
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
<a name="add" class="tsd-anchor"></a>
<h3>add</h3>
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface tsd-is-external">
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
<li class="tsd-signature tsd-kind-icon">add<span class="tsd-signature-symbol">(</span>value<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">this</span></li>
</ul>
<ul class="tsd-descriptions">
Expand Down Expand Up @@ -180,10 +181,10 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">this</spa
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface tsd-is-external">
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
<a name="addall" class="tsd-anchor"></a>
<h3>add<wbr>All</h3>
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface tsd-is-external">
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
<li class="tsd-signature tsd-kind-icon">add<wbr>All<span class="tsd-signature-symbol">(</span>buffer<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">ArrayBuffer</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">this</span></li>
</ul>
<ul class="tsd-descriptions">
Expand Down Expand Up @@ -214,10 +215,10 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">this</spa
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface tsd-is-external">
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
<a name="pause" class="tsd-anchor"></a>
<h3>pause</h3>
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface tsd-is-external">
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
<li class="tsd-signature tsd-kind-icon">pause<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">this</span></li>
</ul>
<ul class="tsd-descriptions">
Expand Down Expand Up @@ -246,7 +247,7 @@ <h3>pause</h3>
.pause()
.add(<span class="hljs-number">4</span>).add(<span class="hljs-number">5</span>).add(<span class="hljs-number">6</span>)
.reset() <span class="hljs-comment">//cancels [4, 5, 6]</span>
.resume()
.resume() <span class="hljs-comment">//resumes []</span>
.resume() <span class="hljs-comment">//resumes [1, 2, 3]</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Uint8Array</span>(gb.toBuffer())) <span class="hljs-comment">//Uint8Array [ 1, 2, 3 ]</span>
</code></pre>
Expand All @@ -255,10 +256,10 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">this</spa
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface tsd-is-external">
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
<a name="reset" class="tsd-anchor"></a>
<h3>reset</h3>
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface tsd-is-external">
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
<li class="tsd-signature tsd-kind-icon">reset<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">this</span></li>
</ul>
<ul class="tsd-descriptions">
Expand Down Expand Up @@ -286,10 +287,10 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">this</spa
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface tsd-is-external">
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
<a name="resume" class="tsd-anchor"></a>
<h3>resume</h3>
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface tsd-is-external">
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
<li class="tsd-signature tsd-kind-icon">resume<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">this</span></li>
</ul>
<ul class="tsd-descriptions">
Expand Down Expand Up @@ -332,25 +333,25 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">this</spa
<ul class="before-current">
</ul>
<ul class="current">
<li class="current tsd-kind-interface tsd-parent-kind-external-module tsd-is-external">
<li class="current tsd-kind-class tsd-parent-kind-external-module tsd-is-external">
<a href="_lib_appendable_.appendablebuffer.html" class="tsd-kind-icon">Appendable<wbr>Buffer</a>
<ul>
<li class=" tsd-kind-property tsd-parent-kind-interface tsd-is-external">
<li class=" tsd-kind-property tsd-parent-kind-class tsd-is-external">
<a href="_lib_appendable_.appendablebuffer.html#length" class="tsd-kind-icon">length</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-interface tsd-is-external">
<li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
<a href="_lib_appendable_.appendablebuffer.html#add" class="tsd-kind-icon">add</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-interface tsd-is-external">
<li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
<a href="_lib_appendable_.appendablebuffer.html#addall" class="tsd-kind-icon">add<wbr>All</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-interface tsd-is-external">
<li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
<a href="_lib_appendable_.appendablebuffer.html#pause" class="tsd-kind-icon">pause</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-interface tsd-is-external">
<li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
<a href="_lib_appendable_.appendablebuffer.html#reset" class="tsd-kind-icon">reset</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-interface tsd-is-external">
<li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
<a href="_lib_appendable_.appendablebuffer.html#resume" class="tsd-kind-icon">resume</a>
</li>
</ul>
Expand Down
Loading

0 comments on commit f9b7468

Please sign in to comment.