Skip to content

Commit

Permalink
Update ts-utils to 0.9.5 (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
nev21 authored Apr 26, 2023
1 parent 4eb4484 commit 6f77b53
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 28 deletions.
22 changes: 11 additions & 11 deletions common/config/rush/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
},

"dependencies": {
"@nevware21/ts-utils": ">= 0.9.3 < 2.x"
"@nevware21/ts-utils": ">= 0.9.5 < 2.x"
},
"peerDependencies": {
"typescript": ">=1"
Expand Down
8 changes: 4 additions & 4 deletions lib/src/promise/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import {
arrForEach, arrSlice, dumpObj, getKnownSymbol, hasSymbol, isFunction, isPromiseLike, isUndefined,
throwTypeError, WellKnownSymbols, objToString, scheduleTimeout, ITimerHandler, getWindow, isNode,
getGlobal, ILazyValue, getLazy, getInst, objDefine, objDefineProp
getGlobal, ILazyValue, objDefine, objDefineProp, lazySafeGetInst
} from "@nevware21/ts-utils";
import { doAwait } from "./await";
import { _addDebugState, _debugLog, _promiseDebugEnabled } from "./debug";
Expand All @@ -29,7 +29,7 @@ let _currentPromiseId: number[] = [];
let _uniquePromiseId = 0;
let _unhandledRejectionTimeout = 10;

let _hasPromiseRejectionEvent: ILazyValue<boolean>;
let _hasPromiseRejectionEvent: ILazyValue<any>;

function dumpFnObj(value: any) {
if (isFunction(value)) {
Expand Down Expand Up @@ -63,7 +63,7 @@ export function _createPromise<T>(newPromise: PromiseCreatorFn, processor: Promi
let _unHandledRejectionHandler: ITimerHandler = null;
let _thePromise: IPromise<T>;

!_hasPromiseRejectionEvent && (_hasPromiseRejectionEvent = getLazy(() => !!getInst(STR_PROMISE + "RejectionEvent")));
!_hasPromiseRejectionEvent && (_hasPromiseRejectionEvent = lazySafeGetInst(STR_PROMISE + "RejectionEvent"));

// https://tc39.es/ecma262/#sec-promise.prototype.then
const _then = <TResult1 = T, TResult2 = never>(onResolved?: ResolvedPromiseHandler<T, TResult1>, onRejected?: RejectedPromiseHandler<TResult2>): IPromise<TResult1 | TResult2> => {
Expand Down Expand Up @@ -216,7 +216,7 @@ export function _createPromise<T>(newPromise: PromiseCreatorFn, processor: Promi
objDefine(theEvt, "promise", { g: () => _thePromise });
theEvt.reason = _settledValue;
return theEvt;
}, _hasPromiseRejectionEvent.v);
}, !!_hasPromiseRejectionEvent.v);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/promise/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT license.
*/

import { dumpObj, getDocument, getInst, getLazy, ILazyValue } from "@nevware21/ts-utils";
import { dumpObj, getDocument, safeGetLazy, ILazyValue, getInst } from "@nevware21/ts-utils";

const DISPATCH_EVENT = "dispatchEvent";
let _hasInitEvent: ILazyValue<boolean>;
Expand All @@ -22,14 +22,14 @@ let _hasInitEvent: ILazyValue<boolean>;
export function emitEvent(target: any, evtName: string, populateEvent: (theEvt: Event | any) => Event | any, useNewEvent: boolean) {

let doc = getDocument();
!_hasInitEvent && (_hasInitEvent = getLazy(() => {
!_hasInitEvent && (_hasInitEvent = safeGetLazy(() => {
let evt: any;
if (doc && doc.createEvent) {
evt = doc.createEvent("Event");
}

return (!!evt && evt.initEvent);
}));
}, null));

let theEvt: Event = _hasInitEvent.v ? doc.createEvent("Event") : (useNewEvent ? new Event(evtName) : {} as Event);
populateEvent && populateEvent(theEvt);
Expand Down
10 changes: 2 additions & 8 deletions lib/src/promise/nativePromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { _createAllPromise, _createRejectedPromise, _createResolvedPromise } fro
import { IPromise } from "../interfaces/IPromise";
import { ePromiseState, STRING_STATES } from "../internal/state";
import { PromiseExecutor } from "../interfaces/types";
import { dumpObj, getInst, getLazy, ILazyValue, isFunction, objDefineProp, throwTypeError } from "@nevware21/ts-utils";
import { dumpObj, lazySafeGetInst, ILazyValue, isFunction, objDefineProp, throwTypeError } from "@nevware21/ts-utils";
import { STR_PROMISE } from "../internal/constants";

let _isPromiseSupported: ILazyValue<PromiseConstructor>;
Expand All @@ -30,13 +30,7 @@ let _isPromiseSupported: ILazyValue<PromiseConstructor>;
* @param timeout - Optional timeout to wait before processing the items, defaults to zero.
*/
export function createNativePromise<T>(executor: PromiseExecutor<T>, timeout?: number): IPromise<T> {
!_isPromiseSupported && (_isPromiseSupported = getLazy(() => {
try {
return getInst(STR_PROMISE);
} catch(e) {
// eslint-disable-next-line no-empty
}
}));
!_isPromiseSupported && (_isPromiseSupported = lazySafeGetInst(STR_PROMISE));

const PrmCls = _isPromiseSupported.v;
if (!PrmCls) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"node": ">= 0.8.0"
},
"dependencies": {
"@nevware21/ts-utils": ">= 0.9.3 < 2.x"
"@nevware21/ts-utils": ">= 0.9.5 < 2.x"
},
"peerDependencies": {
"typescript": ">=1"
Expand Down

0 comments on commit 6f77b53

Please sign in to comment.