Skip to content

Commit

Permalink
improving TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Aug 27, 2019
1 parent 7819cbb commit 5e0df3c
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 27 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![Build Status](https://travis-ci.org/vitaly-t/spex.svg?branch=master)](https://travis-ci.org/vitaly-t/spex)
[![Coverage Status](https://coveralls.io/repos/vitaly-t/spex/badge.svg?branch=master)](https://coveralls.io/r/vitaly-t/spex?branch=master)
[![Downloads Count](http://img.shields.io/npm/dm/spex.svg)](https://www.npmjs.com/package/spex)
[![Join the chat at https://gitter.im/vitaly-t/spex](https://badges.gitter.im/vitaly-t/spex.svg)](https://gitter.im/vitaly-t/spex?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[batch], [page], [sequence] - promise methods for the following patterns:
Expand All @@ -22,13 +21,14 @@ $ npm install spex
* For any [Promises/A+] library: [Promise], [Bluebird], [When], [Q], [RSVP], etc.

```js
var promise = require('bluebird');
var spex = require('spex')(promise);
const promise = require('bluebird');
const spex = require('spex')(promise);
```

* For ES6 Promise:

```js
var spex = require('spex')(Promise);
const spex = require('spex')(Promise);
```

See also: [client-side usage](http://vitaly-t.github.io/spex/tutorial-client.html).
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spex",
"version": "2.3.0",
"version": "3.0.0",
"description": "Specialized Promise Extensions",
"main": "lib/index.js",
"typings": "typescript/spex.d.ts",
Expand All @@ -10,7 +10,7 @@
"coverage": "istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test",
"travis": "npm run lint && istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test --captureExceptions && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"browserify": "browserify lib/index.js -s spexLib -o spex.js",
"lint": "./node_modules/.bin/eslint ./lib ./test/**/*Spec.js"
"lint": "./node_modules/.bin/eslint ./lib ./test/**/*.spec.js"
},
"files": [
"lib",
Expand Down
8 changes: 4 additions & 4 deletions test/typescript/batch.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as spexLib from '../../typescript/spex';
import {IArrayExt} from '../../typescript/spex';

var spex = spexLib(Promise);
const spex = spexLib(Promise);

type BatchError = spexLib.errors.BatchError;

spex.batch([])
.then((data: IArrayExt<any>) => {
var r = data[0].anything;
var d: number = data.duration;
const r = data[0].anything;
const d: number = data.duration;
})
.catch((error: BatchError) => {
var duration: number = error.stat.duration;
const duration: number = error.stat.duration;
});
2 changes: 1 addition & 1 deletion test/typescript/entry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as spexLib from '../../typescript/spex';

var main: spexLib.ISpex;
let main: spexLib.ISpex;

main = spexLib(Promise);
6 changes: 3 additions & 3 deletions test/typescript/page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as spexLib from '../../typescript/spex';
import {IPageResult} from '../../typescript/spex';

var spex = spexLib(Promise);
const spex = spexLib(Promise);

function source() {

Expand All @@ -11,8 +11,8 @@ type PageError = spexLib.errors.PageError;

spex.page(source)
.then((data: IPageResult) => {
var p: number = data.pages;
const p: number = data.pages;
})
.catch((error: PageError) => {
var duration: number = error.duration;
const duration: number = error.duration;
});
12 changes: 6 additions & 6 deletions test/typescript/sequence.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as spexLib from '../../typescript/spex';
import {ISequenceResult, IArrayExt} from '../../typescript/spex';

var spex = spexLib(Promise);
const spex = spexLib(Promise);

function source() {

Expand All @@ -13,19 +13,19 @@ type SequenceError = spexLib.errors.SequenceError;
spex.sequence(source)
.then((data: ISequenceResult | IArrayExt<any>) => {
const actualData = <ISequenceResult>data;
var d = actualData.duration;
var t = actualData.total;
const d = actualData.duration;
const t = actualData.total;
})
.catch((error: SequenceError) => {
var duration: number = error.duration;
const duration: number = error.duration;
});

// sequence with tracking:
spex.sequence(source, {track: true})
.then((data: ISequenceResult | IArrayExt<any>) => {
const actualData = <IArrayExt<any>>data;
var r = actualData[0].anything;
const r = actualData[0].anything;
})
.catch((error: SequenceError) => {
var msg: string = error.message;
const msg: string = error.message;
});
4 changes: 2 additions & 2 deletions test/typescript/stream.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as spexLib from '../../typescript/spex';
import {IStreamReadResult} from '../../typescript/spex';

var spex = spexLib(Promise);
const spex = spexLib(Promise);

function cb() {

}

spex.stream.read(123, cb)
.then((data: IStreamReadResult) => {
var c: number = data.calls;
const c: number = data.calls;
})
.catch((error: any) => {
});
8 changes: 4 additions & 4 deletions typescript/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## TypeScript for SPEX

Complete TypeScript 2.x declarations for the [spex] module.
Complete TypeScript 3.x declarations for the [spex] module.

### Inclusion

Expand All @@ -11,15 +11,15 @@ Typescript should be able to pick up the definitions without any manual configur
```ts
import * as spexLib from "spex";

var spex:spexLib.ISpex = spexLib(Promise);
const spex:spexLib.ISpex = spexLib(Promise);

type BatchError = spexLib.errors.BatchError;

spex.batch([1, 2, 3])
.then(data=> {
.then(data => {
var r = data[0].anything;
})
.catch(error=> {
.catch(error => {
// error type is either TypeError or BatchError
});
```
Expand Down
2 changes: 1 addition & 1 deletion typescript/spex.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
////////////////////////////////////////
// Requires SPEX v2.3.0 or later.
// Requires SPEX v3.0.0 or later.
////////////////////////////////////////

declare namespace spex {
Expand Down

0 comments on commit 5e0df3c

Please sign in to comment.