From 7b15cb8e419624ea322c7b46bb4c6b9a05eb284a Mon Sep 17 00:00:00 2001 From: Dmitriy Mozgovoy Date: Thu, 10 Sep 2020 00:44:52 +0300 Subject: [PATCH] Updated README.md --- README.md | 27 ++++++++++++++++++++++----- jsdoc2md/README.hbs.md | 27 ++++++++++++++++++++++----- lib/c-promise.js | 8 ++------ package.json | 2 +- playground/basic.js | 10 +++++++--- 5 files changed, 54 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 558078a..f49c4a6 100644 --- a/README.md +++ b/README.md @@ -30,13 +30,22 @@ has lost its relevance to you. Install for node.js using npm/yarn: ``` bash -$ npm install c-promise +$ npm install c-promise2 ``` ``` bash -$ yarn add c-promise +$ yarn add c-promise2 ``` +#### CDN +- [development UMD version](https://unpkg.com/c-promise2@0.1.0/dist/dev/c-promise.umd.js) + +- [production UMD version](https://unpkg.com/c-promise2@0.1.0/dist/c-promise.umd.js) + +- [production CommonJS version](https://unpkg.com/c-promise2@0.1.0/dist/c-promise.cjs.js) + +- [production ESM version](https://unpkg.com/c-promise2@0.1.0/dist/c-promise.mjs) + ## Features / Advantages - there are no any dependencies (except [native] Promise), browser support - cancellation sequence @@ -54,6 +63,10 @@ $ yarn add c-promise ## Live Example +[Live browser example](https://jsfiddle.net/DigitalBrain/g0dv5L8c/3/) + +[Live nodejs example](https://runkit.com/digitalbrainjs/runkit-npm-c-promise2) + Browser playground with fetch ## Playground @@ -111,10 +124,14 @@ echoChainState(); chain .then((value) => { - log(`Done with value '${value}'`); - }, (err) => { - log(`cancelled with error : ${err} on '${err.scope.label()}'`); // [1006ms] CanceledError: canceled + log(`Done with value '${value}'`); // [1006ms] CanceledError: canceled }).label('final') + .catch((err)=>{ + log(`cancelled with error : ${err} on '${err.scope.label()}'`); // [1006ms] CanceledError: canceled + }, CPromise.CanceledError) + .catch(err=>{ + log(`Some other error occurred: ${err}`); + }) .finally(() => { echoChainState(); }); diff --git a/jsdoc2md/README.hbs.md b/jsdoc2md/README.hbs.md index 99ac588..8ab3a46 100644 --- a/jsdoc2md/README.hbs.md +++ b/jsdoc2md/README.hbs.md @@ -30,13 +30,22 @@ has lost its relevance to you. Install for node.js using npm/yarn: ``` bash -$ npm install c-promise +$ npm install c-promise2 ``` ``` bash -$ yarn add c-promise +$ yarn add c-promise2 ``` +#### CDN +- [development UMD version](https://unpkg.com/c-promise2@0.1.0/dist/dev/c-promise.umd.js) + +- [production UMD version](https://unpkg.com/c-promise2@0.1.0/dist/c-promise.umd.js) + +- [production CommonJS version](https://unpkg.com/c-promise2@0.1.0/dist/c-promise.cjs.js) + +- [production ESM version](https://unpkg.com/c-promise2@0.1.0/dist/c-promise.mjs) + ## Features / Advantages - there are no any dependencies (except [native] Promise), browser support - cancellation sequence @@ -54,6 +63,10 @@ $ yarn add c-promise ## Live Example +[Live browser example](https://jsfiddle.net/DigitalBrain/g0dv5L8c/3/) + +[Live nodejs example](https://runkit.com/digitalbrainjs/runkit-npm-c-promise2) + Browser playground with fetch ## Playground @@ -111,10 +124,14 @@ echoChainState(); chain .then((value) => { - log(`Done with value '${value}'`); - }, (err) => { - log(`cancelled with error : ${err} on '${err.scope.label()}'`); // [1006ms] CanceledError: canceled + log(`Done with value '${value}'`); // [1006ms] CanceledError: canceled }).label('final') + .catch((err)=>{ + log(`cancelled with error : ${err} on '${err.scope.label()}'`); // [1006ms] CanceledError: canceled + }, CPromise.CanceledError) + .catch(err=>{ + log(`Some other error occurred: ${err}`); + }) .finally(() => { echoChainState(); }); diff --git a/lib/c-promise.js b/lib/c-promise.js index 4b69834..76fd726 100644 --- a/lib/c-promise.js +++ b/lib/c-promise.js @@ -668,10 +668,6 @@ class CPromise extends Promise { catch(onRejected, filter){ if(filter){ - if(!(filter instanceof Error)){ - throw TypeError('filter argument must be an error constructor'); - } - return super.catch((err)=>{ if(err instanceof filter){ onRejected(err); @@ -776,12 +772,12 @@ function bindMethod(prototype, methodName) { throw Error(`Property ${methodName} doesn't exists`); } const method = descriptor.value; - let bound; + const boundSymbol= Symbol(`${methodName}Bound`); Object.defineProperty(prototype, methodName, { get() { const context = this; - return bound || (bound = function () { + return this[boundSymbol] || (this[boundSymbol] = function () { return method.apply(context, arguments); }) } diff --git a/package.json b/package.json index 4c0fb6a..e0dd93f 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "c-promise", + "name": "c-promise2", "version": "0.1.0", "description": "Cancelable promise chain with progress capturing and other extra features", "author": { diff --git a/playground/basic.js b/playground/basic.js index 8973d6f..32af47e 100644 --- a/playground/basic.js +++ b/playground/basic.js @@ -30,10 +30,14 @@ echoChainState(); chain .then((value) => { - log(`Done with value '${value}'`); - }, (err) => { - log(`cancelled with error : ${err} on '${err.scope.label()}'`); // [1006ms] CanceledError: canceled + log(`Done with value '${value}'`); // [1006ms] CanceledError: canceled }).label('final') + .catch((err)=>{ + log(`cancelled with error : ${err} on '${err.scope.label()}'`); // [1006ms] CanceledError: canceled + }, CPromise.CanceledError) + .catch(err=>{ + log(`Some other error occurred: ${err}`); + }) .finally(() => { echoChainState(); });