@litert/core
Advanced tools
Comparing version 1.0.2 to 1.0.3
# Changes Logs | ||
## v1.0.3 | ||
- Fixed: Methods `reject` and `resolve` in RawPromise couldn't work without | ||
`this` binding. | ||
## v1.0.2 | ||
@@ -4,0 +9,0 @@ |
@@ -32,2 +32,6 @@ /** | ||
/** | ||
* The Promise object. | ||
*/ | ||
promise: Promise<T>; | ||
/** | ||
* The Promise rejector method. | ||
@@ -37,3 +41,3 @@ * | ||
*/ | ||
reject(e: E): void; | ||
resolve: IPromiseResolver<T>; | ||
/** | ||
@@ -44,11 +48,5 @@ * The Promise resolver method. | ||
*/ | ||
resolve(data?: T): void; | ||
/** | ||
* The Promise object. | ||
*/ | ||
promise: Promise<T>; | ||
protected _resolve: IPromiseResolver<T>; | ||
protected _reject: IPromiseRejector<E>; | ||
reject: IPromiseRejector<E>; | ||
constructor(); | ||
} | ||
//# sourceMappingURL=class.RawPromise.d.ts.map |
@@ -27,24 +27,8 @@ "use strict"; | ||
this.promise = new Promise((resolve, reject) => { | ||
this._resolve = resolve; | ||
this._reject = reject; | ||
this.resolve = resolve; | ||
this.reject = reject; | ||
}); | ||
} | ||
/** | ||
* The Promise rejector method. | ||
* | ||
* If this method is called, promise will be REJECTED. | ||
*/ | ||
reject(e) { | ||
return this._reject(e); | ||
} | ||
/** | ||
* The Promise resolver method. | ||
* | ||
* If this method is called, promise will be RESOLVED. | ||
*/ | ||
resolve(data) { | ||
return this._resolve(data); | ||
} | ||
} | ||
exports.RawPromise = RawPromise; | ||
//# sourceMappingURL=class.RawPromise.js.map |
@@ -30,2 +30,4 @@ /** | ||
private _handleTimeout; | ||
private _reject; | ||
private _resolve; | ||
/** | ||
@@ -40,19 +42,4 @@ * The constructor of a timeout-promise. | ||
constructor(msTimeout: number, timeoutError: E, autoStart?: boolean, handleTimeout?: IPromiseTimeoutResultHandler<T, E>); | ||
private _initMethods; | ||
/** | ||
* The Promise rejector method. | ||
* | ||
* If this method is called, promise will be REJECTED. | ||
* | ||
* If it's already timeont, then do nothing. | ||
*/ | ||
reject(e: E): void; | ||
/** | ||
* The Promise resolver method. | ||
* | ||
* If this method is called, promise will be RESOLVED. | ||
* | ||
* If it's already timeont, then do nothing. | ||
*/ | ||
resolve(data?: T): void; | ||
/** | ||
* Start the timer. | ||
@@ -59,0 +46,0 @@ */ |
@@ -30,2 +30,4 @@ "use strict"; | ||
super(); | ||
this._reject = this.reject; | ||
this._resolve = this.resolve; | ||
this._msTimeout = msTimeout; | ||
@@ -36,2 +38,3 @@ this._timeoutError = timeoutError; | ||
} | ||
this._initMethods(); | ||
if (autoStart) { | ||
@@ -41,47 +44,35 @@ this.start(); | ||
} | ||
/** | ||
* The Promise rejector method. | ||
* | ||
* If this method is called, promise will be REJECTED. | ||
* | ||
* If it's already timeont, then do nothing. | ||
*/ | ||
reject(e) { | ||
/** | ||
* If no timer, it means already timeout, so do nothing. | ||
*/ | ||
if (null === this._timer) { | ||
this._handleTimeout && this._handleTimeout({ | ||
"error": e, | ||
"value": undefined | ||
}); | ||
return; | ||
} | ||
clearTimeout(this._timer); | ||
this._timer = null; | ||
this._reject(e); | ||
_initMethods() { | ||
this.reject = (e) => { | ||
/** | ||
* If no timer, it means already timeout, so do nothing. | ||
*/ | ||
if (null === this._timer) { | ||
this._handleTimeout && this._handleTimeout({ | ||
"error": e, | ||
"value": undefined | ||
}); | ||
return; | ||
} | ||
clearTimeout(this._timer); | ||
this._timer = null; | ||
this._reject(e); | ||
}; | ||
this.resolve = (data) => { | ||
/** | ||
* If no timer, it means already timeout, so do nothing. | ||
*/ | ||
if (null === this._timer) { | ||
this._handleTimeout && this._handleTimeout({ | ||
"error": null, | ||
"value": data | ||
}); | ||
return; | ||
} | ||
clearTimeout(this._timer); | ||
this._timer = null; | ||
this._resolve(data); | ||
}; | ||
} | ||
/** | ||
* The Promise resolver method. | ||
* | ||
* If this method is called, promise will be RESOLVED. | ||
* | ||
* If it's already timeont, then do nothing. | ||
*/ | ||
resolve(data) { | ||
/** | ||
* If no timer, it means already timeout, so do nothing. | ||
*/ | ||
if (null === this._timer) { | ||
this._handleTimeout && this._handleTimeout({ | ||
"error": null, | ||
"value": data | ||
}); | ||
return; | ||
} | ||
clearTimeout(this._timer); | ||
this._timer = null; | ||
this._resolve(data); | ||
} | ||
/** | ||
* Start the timer. | ||
@@ -88,0 +79,0 @@ */ |
{ | ||
"name": "@litert/core", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "The core of LiteRT.", | ||
@@ -11,3 +11,3 @@ "main": "lib/index.js", | ||
"rebuild": "npm run clean && npm run lint && npm run build", | ||
"test": "echo See directory sources/samples", | ||
"test": "echo See directory src/samples", | ||
"clean": "rm -rf lib samples", | ||
@@ -34,4 +34,4 @@ "lint": "tslint -p . -c tslint.json" | ||
"devDependencies": { | ||
"typescript": "^3.1.4" | ||
"typescript": "^3.2.2" | ||
} | ||
} |
@@ -16,4 +16,13 @@ # LiteRT/Core | ||
## Requirements | ||
- Node.js v8.x (Or newer) | ||
- TypeScript v3.1.x (Or newer) | ||
## Documents | ||
- [简体中文版](./docs/zh-CN/README.md) | ||
## License | ||
This library is published under [Apache-2.0](./LICENSE) license. |
@@ -29,5 +29,3 @@ "use strict"; | ||
}); | ||
setTimeout(() => { | ||
ret.resolve("Hello"); | ||
}, 300); | ||
setTimeout(ret.resolve, 300, "hello"); | ||
try { | ||
@@ -34,0 +32,0 @@ await ret.promise; |
@@ -36,2 +36,7 @@ /** | ||
/** | ||
* The Promise object. | ||
*/ | ||
public promise: Promise<T>; | ||
/** | ||
* The Promise rejector method. | ||
@@ -41,7 +46,4 @@ * | ||
*/ | ||
public reject(e: E): void { | ||
public resolve!: IPromiseResolver<T>; | ||
return this._reject(e); | ||
} | ||
/** | ||
@@ -52,16 +54,4 @@ * The Promise resolver method. | ||
*/ | ||
public resolve(data?: T): void { | ||
public reject!: IPromiseRejector<E>; | ||
return this._resolve(data); | ||
} | ||
/** | ||
* The Promise object. | ||
*/ | ||
public promise: Promise<T>; | ||
protected _resolve!: IPromiseResolver<T>; | ||
protected _reject!: IPromiseRejector<E>; | ||
public constructor() { | ||
@@ -71,6 +61,6 @@ | ||
this._resolve = resolve; | ||
this._reject = reject; | ||
this.resolve = resolve; | ||
this.reject = reject; | ||
}); | ||
} | ||
} |
@@ -17,3 +17,3 @@ /** | ||
import { RawPromise } from "./class.RawPromise"; | ||
import { RawPromise, IPromiseRejector, IPromiseResolver } from "./class.RawPromise"; | ||
@@ -46,2 +46,6 @@ export type ITimeoutResult<T, E> = { | ||
private _reject: IPromiseRejector<E>; | ||
private _resolve: IPromiseResolver<T>; | ||
/** | ||
@@ -64,2 +68,5 @@ * The constructor of a timeout-promise. | ||
this._reject = this.reject; | ||
this._resolve = this.resolve; | ||
this._msTimeout = msTimeout; | ||
@@ -73,2 +80,4 @@ this._timeoutError = timeoutError; | ||
this._initMethods(); | ||
if (autoStart) { | ||
@@ -80,56 +89,45 @@ | ||
/** | ||
* The Promise rejector method. | ||
* | ||
* If this method is called, promise will be REJECTED. | ||
* | ||
* If it's already timeont, then do nothing. | ||
*/ | ||
public reject(e: E): void { | ||
private _initMethods(): void { | ||
/** | ||
* If no timer, it means already timeout, so do nothing. | ||
*/ | ||
if (null === this._timer) { | ||
this.reject = (e: E): void => { | ||
this._handleTimeout && this._handleTimeout({ | ||
"error": e, | ||
"value": undefined | ||
}); | ||
/** | ||
* If no timer, it means already timeout, so do nothing. | ||
*/ | ||
if (null === this._timer) { | ||
return; | ||
} | ||
this._handleTimeout && this._handleTimeout({ | ||
"error": e, | ||
"value": undefined | ||
}); | ||
clearTimeout(this._timer); | ||
this._timer = null; | ||
return; | ||
} | ||
this._reject(e); | ||
} | ||
clearTimeout(this._timer); | ||
this._timer = null; | ||
/** | ||
* The Promise resolver method. | ||
* | ||
* If this method is called, promise will be RESOLVED. | ||
* | ||
* If it's already timeont, then do nothing. | ||
*/ | ||
public resolve(data?: T): void { | ||
this._reject(e); | ||
}; | ||
/** | ||
* If no timer, it means already timeout, so do nothing. | ||
*/ | ||
if (null === this._timer) { | ||
this.resolve = (data?: T): void => { | ||
this._handleTimeout && this._handleTimeout({ | ||
"error": null, | ||
"value": data | ||
}); | ||
/** | ||
* If no timer, it means already timeout, so do nothing. | ||
*/ | ||
if (null === this._timer) { | ||
return; | ||
} | ||
this._handleTimeout && this._handleTimeout({ | ||
"error": null, | ||
"value": data | ||
}); | ||
clearTimeout(this._timer); | ||
this._timer = null; | ||
return; | ||
} | ||
this._resolve(data); | ||
clearTimeout(this._timer); | ||
this._timer = null; | ||
this._resolve(data); | ||
}; | ||
} | ||
@@ -136,0 +134,0 @@ |
@@ -40,8 +40,4 @@ /** | ||
setTimeout(() => { | ||
setTimeout(ret.resolve, 300, "hello"); | ||
ret.resolve("Hello"); | ||
}, 300); | ||
try { | ||
@@ -48,0 +44,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109379
74
2297
28