@alterior/common 3.15.0 → 3.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cache.d.ts +2 -2
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +2 -1
- package/dist/cache.js.map +1 -1
- package/dist/cache.test.js.map +1 -1
- package/dist/clone.d.ts +5 -2
- package/dist/clone.d.ts.map +1 -1
- package/dist/clone.js +4 -6
- package/dist/clone.js.map +1 -1
- package/dist/colors.d.ts +2 -56
- package/dist/colors.d.ts.map +1 -1
- package/dist/colors.js +3 -8
- package/dist/colors.js.map +1 -1
- package/dist/console.d.ts +0 -8
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js.map +1 -1
- package/dist/constructor.d.ts.map +1 -1
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +1 -1
- package/dist/decorators.js.map +1 -1
- package/dist/errors.d.ts +8 -6
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/lazy-promise.d.ts +1 -1
- package/dist/lazy-promise.d.ts.map +1 -1
- package/dist/lazy-promise.js.map +1 -1
- package/dist/locks.d.ts +3 -3
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js.map +1 -1
- package/dist/object-entries-typed.d.ts +3 -0
- package/dist/object-entries-typed.d.ts.map +1 -0
- package/dist/object-entries-typed.js +11 -0
- package/dist/object-entries-typed.js.map +1 -0
- package/dist/presentation.d.ts +1 -1
- package/dist/presentation.d.ts.map +1 -1
- package/dist/presentation.js +1 -0
- package/dist/presentation.js.map +1 -1
- package/dist/presentation.test.js.map +1 -1
- package/dist/serializer.d.ts +5 -0
- package/dist/serializer.d.ts.map +1 -1
- package/dist/serializer.js +7 -11
- package/dist/serializer.js.map +1 -1
- package/dist/timeout.js.map +1 -1
- package/dist/zones.d.ts +1 -1
- package/dist/zones.d.ts.map +1 -1
- package/dist/zones.js +5 -2
- package/dist/zones.js.map +1 -1
- package/dist.esm/cache.d.ts +2 -2
- package/dist.esm/cache.d.ts.map +1 -1
- package/dist.esm/cache.js +2 -1
- package/dist.esm/cache.js.map +1 -1
- package/dist.esm/cache.test.js.map +1 -1
- package/dist.esm/clone.d.ts +5 -2
- package/dist.esm/clone.d.ts.map +1 -1
- package/dist.esm/clone.js +4 -6
- package/dist.esm/clone.js.map +1 -1
- package/dist.esm/colors.d.ts +2 -56
- package/dist.esm/colors.d.ts.map +1 -1
- package/dist.esm/colors.js +3 -8
- package/dist.esm/colors.js.map +1 -1
- package/dist.esm/console.d.ts +0 -8
- package/dist.esm/console.d.ts.map +1 -1
- package/dist.esm/console.js.map +1 -1
- package/dist.esm/constructor.d.ts.map +1 -1
- package/dist.esm/decorators.d.ts.map +1 -1
- package/dist.esm/decorators.js +1 -1
- package/dist.esm/decorators.js.map +1 -1
- package/dist.esm/errors.d.ts +8 -6
- package/dist.esm/errors.d.ts.map +1 -1
- package/dist.esm/errors.js.map +1 -1
- package/dist.esm/lazy-promise.d.ts +1 -1
- package/dist.esm/lazy-promise.d.ts.map +1 -1
- package/dist.esm/lazy-promise.js.map +1 -1
- package/dist.esm/locks.d.ts +3 -3
- package/dist.esm/locks.d.ts.map +1 -1
- package/dist.esm/locks.js.map +1 -1
- package/dist.esm/object-entries-typed.d.ts +3 -0
- package/dist.esm/object-entries-typed.d.ts.map +1 -0
- package/dist.esm/object-entries-typed.js +7 -0
- package/dist.esm/object-entries-typed.js.map +1 -0
- package/dist.esm/presentation.d.ts +1 -1
- package/dist.esm/presentation.d.ts.map +1 -1
- package/dist.esm/presentation.js +1 -0
- package/dist.esm/presentation.js.map +1 -1
- package/dist.esm/presentation.test.js.map +1 -1
- package/dist.esm/serializer.d.ts +5 -0
- package/dist.esm/serializer.d.ts.map +1 -1
- package/dist.esm/serializer.js +7 -11
- package/dist.esm/serializer.js.map +1 -1
- package/dist.esm/timeout.js.map +1 -1
- package/dist.esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist.esm/zones.d.ts +1 -1
- package/dist.esm/zones.d.ts.map +1 -1
- package/dist.esm/zones.js +5 -2
- package/dist.esm/zones.js.map +1 -1
- package/package.json +2 -2
- package/src/cache.test.ts +2 -2
- package/src/cache.ts +25 -24
- package/src/clone.ts +20 -9
- package/src/colors.ts +16 -19
- package/src/console.ts +8 -17
- package/src/constructor.ts +1 -1
- package/src/decorators.ts +1 -1
- package/src/errors.ts +30 -30
- package/src/lazy-promise.ts +4 -4
- package/src/locks.ts +3 -3
- package/src/object-entries-typed.ts +7 -0
- package/src/presentation.test.ts +9 -9
- package/src/presentation.ts +30 -30
- package/src/serializer.ts +17 -6
- package/src/timeout.ts +1 -1
- package/src/zones.ts +23 -23
- package/tsconfig.tsbuildinfo +1 -1
package/src/lazy-promise.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export class LazyPromise<T> extends Promise<T> {
|
|
7
7
|
constructor(
|
|
8
|
-
private fulfiller
|
|
8
|
+
private fulfiller: () => Promise<T>
|
|
9
9
|
) {
|
|
10
10
|
super((resolve, reject) => {
|
|
11
11
|
this._resolve = resolve;
|
|
@@ -14,8 +14,8 @@ export class LazyPromise<T> extends Promise<T> {
|
|
|
14
14
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
private _resolve
|
|
18
|
-
private _reject
|
|
17
|
+
private _resolve!: (result: T) => void;
|
|
18
|
+
private _reject!: (reason?: any) => void;
|
|
19
19
|
|
|
20
20
|
fulfill() {
|
|
21
21
|
if (!this.realPromise) {
|
|
@@ -26,7 +26,7 @@ export class LazyPromise<T> extends Promise<T> {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
private realPromise
|
|
29
|
+
private realPromise?: Promise<void>;
|
|
30
30
|
|
|
31
31
|
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2> {
|
|
32
32
|
this.fulfill();
|
package/src/locks.ts
CHANGED
|
@@ -8,7 +8,7 @@ export class Lock {
|
|
|
8
8
|
constructor() {
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
private _ready : Promise<void
|
|
11
|
+
private _ready : Promise<void> | undefined;
|
|
12
12
|
private static _namedLocks : Map<any, Lock>;
|
|
13
13
|
|
|
14
14
|
static forToken<T extends Lock>(this : { new() : T }, token : any): T {
|
|
@@ -37,7 +37,7 @@ export class Lock {
|
|
|
37
37
|
return lock;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
protected async executeCallback(cb) {
|
|
40
|
+
protected async executeCallback(cb: Function) {
|
|
41
41
|
return await cb();
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -76,7 +76,7 @@ export class ZoneLock extends Lock {
|
|
|
76
76
|
super();
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
protected async executeCallback(cb) {
|
|
79
|
+
protected async executeCallback<T>(cb: () => Promise<T> | T): Promise<T> {
|
|
80
80
|
return await AsyncZone.run(cb);
|
|
81
81
|
}
|
|
82
82
|
}
|
package/src/presentation.test.ts
CHANGED
|
@@ -13,14 +13,14 @@ suite(describe => {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function Nothing() {
|
|
16
|
-
return (target, ...args) => target;
|
|
16
|
+
return (target: any, ...args: any[]) => target;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
@Nothing()
|
|
20
20
|
class ApiMovie extends Presentation<Movie> {
|
|
21
|
-
@Expose() description : string;
|
|
22
|
-
@Expose() title : string;
|
|
23
|
-
@Expose() rating : number;
|
|
21
|
+
@Expose() description! : string;
|
|
22
|
+
@Expose() title! : string;
|
|
23
|
+
@Expose() rating! : number;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
let props = ApiMovie.properties;
|
|
@@ -33,9 +33,9 @@ suite(describe => {
|
|
|
33
33
|
expect(titleProp).to.exist
|
|
34
34
|
expect(ratingProp).to.exist
|
|
35
35
|
|
|
36
|
-
expect(descProp
|
|
37
|
-
expect(titleProp
|
|
38
|
-
expect(ratingProp
|
|
36
|
+
expect(descProp!.designType).to.equal(String);
|
|
37
|
+
expect(titleProp!.designType).to.equal(String);
|
|
38
|
+
expect(ratingProp!.designType).to.equal(Number);
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
it('correctly handles subclassing', () => {
|
|
@@ -45,11 +45,11 @@ suite(describe => {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
class ApiAbridgedMovie extends Presentation<Movie> {
|
|
48
|
-
@Expose() title : string;
|
|
48
|
+
@Expose() title! : string;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
class ApiMovie extends ApiAbridgedMovie {
|
|
52
|
-
@Expose() description : string;
|
|
52
|
+
@Expose() description! : string;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
let abridgedPresenter = new ApiAbridgedMovie({ title: 'Title', description: 'Description' });
|
package/src/presentation.ts
CHANGED
|
@@ -6,27 +6,27 @@ import { clone } from "./clone";
|
|
|
6
6
|
export const EXPOSE_PROTOTYPE_STORAGE_KEY = '@alterior/common:Expose';
|
|
7
7
|
|
|
8
8
|
export interface PresentedPropertyOptions {
|
|
9
|
-
useProperty
|
|
10
|
-
class
|
|
11
|
-
defaultValue
|
|
9
|
+
useProperty?: string;
|
|
10
|
+
class?: Constructor<Presentation<any>>;
|
|
11
|
+
defaultValue?: any;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export interface PresentedProperty {
|
|
15
|
-
propertyKey
|
|
16
|
-
options
|
|
17
|
-
designType
|
|
15
|
+
propertyKey: string;
|
|
16
|
+
options: PresentedPropertyOptions;
|
|
17
|
+
designType?: any;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export class PresentationSchema<T> {
|
|
21
|
-
constructor(readonly type
|
|
21
|
+
constructor(readonly type: Constructor<Presentation<T>>) {
|
|
22
22
|
this.populate();
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
private populate() {
|
|
26
|
-
let exposureSets
|
|
26
|
+
let exposureSets: PresentedProperty[][] = [];
|
|
27
27
|
|
|
28
28
|
let prototype = this.type.prototype;
|
|
29
|
-
let prototypes = [
|
|
29
|
+
let prototypes = [];
|
|
30
30
|
|
|
31
31
|
while (prototype) {
|
|
32
32
|
prototypes.push(prototype);
|
|
@@ -38,13 +38,13 @@ export class PresentationSchema<T> {
|
|
|
38
38
|
|
|
39
39
|
// Reverse the order so that the super-most properties appear first,
|
|
40
40
|
// followed by the subproperties.
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
exposureSets = exposureSets.reverse();
|
|
43
43
|
|
|
44
44
|
let exposures = exposureSets
|
|
45
45
|
.reduce((pv, cv) => (pv.push(...cv), pv), [])
|
|
46
46
|
.map(x => clone(x))
|
|
47
|
-
|
|
47
|
+
;
|
|
48
48
|
|
|
49
49
|
for (let exposure of exposures) {
|
|
50
50
|
let key = exposure.propertyKey;
|
|
@@ -54,7 +54,7 @@ export class PresentationSchema<T> {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
let designType = null;
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
for (let prototype of prototypes) {
|
|
59
59
|
designType = Reflect.getMetadata('design:type', prototype, key);
|
|
60
60
|
if (designType)
|
|
@@ -68,7 +68,7 @@ export class PresentationSchema<T> {
|
|
|
68
68
|
this.properties = exposures;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
properties
|
|
71
|
+
properties: PresentedProperty[] = [];
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
@@ -83,7 +83,7 @@ export class PresentationSchema<T> {
|
|
|
83
83
|
*/
|
|
84
84
|
export class Presentation<T> {
|
|
85
85
|
constructor(
|
|
86
|
-
readonly instance
|
|
86
|
+
readonly instance: T
|
|
87
87
|
) {
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -94,39 +94,39 @@ export class Presentation<T> {
|
|
|
94
94
|
* @param this
|
|
95
95
|
* @param array
|
|
96
96
|
*/
|
|
97
|
-
public static from<T extends Presentation<U>, U>(this
|
|
97
|
+
public static from<T extends Presentation<U>, U>(this: Constructor<T>, array: U[]): T[] {
|
|
98
98
|
return array.map(x => new this(x));
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
public static get properties()
|
|
101
|
+
public static get properties(): PresentedProperty[] {
|
|
102
102
|
return new PresentationSchema(this).properties;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
public toJSON() {
|
|
106
106
|
if (!this.instance)
|
|
107
107
|
return null;
|
|
108
|
-
|
|
108
|
+
|
|
109
109
|
let properties = {};
|
|
110
|
-
let exposures
|
|
110
|
+
let exposures: PresentedProperty[] = (this.constructor as any).properties;
|
|
111
111
|
|
|
112
112
|
for (let exposure of exposures) {
|
|
113
113
|
let key = exposure.propertyKey;
|
|
114
114
|
let options = exposure.options;
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
let prototype = Object.getPrototypeOf(this);
|
|
117
117
|
|
|
118
118
|
let propertyType = Reflect.getMetadata('design:type', this.constructor.prototype, key);
|
|
119
119
|
let propertyDescriptor = Object.getOwnPropertyDescriptor(prototype, key);
|
|
120
|
-
let value = this[key];
|
|
120
|
+
let value = (this as any)[key];
|
|
121
121
|
|
|
122
122
|
if (options.useProperty) {
|
|
123
|
-
value = this.instance[options.useProperty];
|
|
123
|
+
value = (this.instance as any)[options.useProperty];
|
|
124
124
|
} else if (!propertyDescriptor || !propertyDescriptor.get) {
|
|
125
125
|
// Data property, fill from original object.
|
|
126
|
-
value = this.instance[key];
|
|
126
|
+
value = (this.instance as any)[key];
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
let entityType
|
|
129
|
+
let entityType: Constructor<Presentation<any>> | undefined;
|
|
130
130
|
|
|
131
131
|
if (options.class) {
|
|
132
132
|
entityType = options.class;
|
|
@@ -141,7 +141,7 @@ export class Presentation<T> {
|
|
|
141
141
|
if (value && value.toJSON)
|
|
142
142
|
value = value.toJSON();
|
|
143
143
|
|
|
144
|
-
properties[key] = value;
|
|
144
|
+
(properties as any)[key] = value;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
return properties;
|
|
@@ -154,7 +154,7 @@ export class Presentation<T> {
|
|
|
154
154
|
*
|
|
155
155
|
* @see Presentation<T>
|
|
156
156
|
*/
|
|
157
|
-
export function Expose(options
|
|
157
|
+
export function Expose(options: PresentedPropertyOptions = {}) {
|
|
158
158
|
return function (target: Object, propertyKey: string, descriptor?: PropertyDescriptor) {
|
|
159
159
|
|
|
160
160
|
if (!target.hasOwnProperty(EXPOSE_PROTOTYPE_STORAGE_KEY)) {
|
|
@@ -164,11 +164,11 @@ export function Expose(options : PresentedPropertyOptions = {}) {
|
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
let exposures
|
|
167
|
+
let exposures: PresentedProperty[] = (target as any)[EXPOSE_PROTOTYPE_STORAGE_KEY];
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
exposures.push(<PresentedProperty>{
|
|
170
|
+
propertyKey: propertyKey,
|
|
171
|
+
options
|
|
172
172
|
});
|
|
173
|
-
|
|
173
|
+
};
|
|
174
174
|
}
|
package/src/serializer.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { objectEntriesTyped } from "./object-entries-typed";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Prepare an object for serialization by removing any fields which are undefined
|
|
3
5
|
* or functions and return the result. The operation is recursive across all subobjects.
|
|
@@ -5,20 +7,29 @@
|
|
|
5
7
|
*
|
|
6
8
|
* @param data
|
|
7
9
|
*/
|
|
8
|
-
export function prepareForSerialization<T>(data : T): T
|
|
10
|
+
export function prepareForSerialization<T>(data : T): T;
|
|
11
|
+
export function prepareForSerialization<T>(data : undefined): undefined;
|
|
12
|
+
export function prepareForSerialization<T>(data : null): null;
|
|
13
|
+
export function prepareForSerialization<T>(data : T | undefined): T | undefined;
|
|
14
|
+
export function prepareForSerialization<T>(data : T | null): T | null;
|
|
15
|
+
export function prepareForSerialization<T>(data : T | undefined | null): T | undefined | null;
|
|
16
|
+
export function prepareForSerialization<T>(data : T | undefined | null): T | undefined | null {
|
|
9
17
|
if (data === undefined || data === null)
|
|
10
|
-
return
|
|
18
|
+
return data;
|
|
11
19
|
|
|
12
|
-
if (data
|
|
13
|
-
data = data
|
|
20
|
+
if ((data as any).toJSON)
|
|
21
|
+
data = (data as any).toJSON();
|
|
14
22
|
|
|
23
|
+
if (data === undefined || data === null)
|
|
24
|
+
return data;
|
|
25
|
+
|
|
15
26
|
if (typeof data !== 'object')
|
|
16
27
|
return data;
|
|
17
28
|
|
|
18
|
-
return
|
|
29
|
+
return objectEntriesTyped(data)
|
|
19
30
|
.filter(x => x[1] !== undefined)
|
|
20
31
|
.filter(x => typeof x[1] !== 'function')
|
|
21
|
-
.map(x => [x[0], prepareForSerialization(x[1])])
|
|
32
|
+
.map(x => [x[0], prepareForSerialization(x[1])] as const)
|
|
22
33
|
.reduce((o, [k,v]) => (o[k] = v, o), <T>{})
|
|
23
34
|
;
|
|
24
35
|
}
|
package/src/timeout.ts
CHANGED
|
@@ -18,7 +18,7 @@ export function timeout(time : number = 0) : Promise<void> {
|
|
|
18
18
|
* @param time
|
|
19
19
|
*/
|
|
20
20
|
export function interval(time : number) : Observable<void> {
|
|
21
|
-
let interval;
|
|
21
|
+
let interval: any;
|
|
22
22
|
return lazySubject({
|
|
23
23
|
start: subject => interval = setInterval(() => subject.next()),
|
|
24
24
|
stop: () => clearInterval(interval)
|
package/src/zones.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { Observable, Subject } from 'rxjs';
|
|
|
15
15
|
* and no further execution is possible.
|
|
16
16
|
*/
|
|
17
17
|
export class AsyncZone {
|
|
18
|
-
public constructor(name
|
|
18
|
+
public constructor(name: string, properties: any = {}) {
|
|
19
19
|
let self = this;
|
|
20
20
|
|
|
21
21
|
this._outside = Zone.current;
|
|
@@ -26,7 +26,7 @@ export class AsyncZone {
|
|
|
26
26
|
onInvoke(delegate, current, target, callback, applyThis, applyArgs, source) {
|
|
27
27
|
return self.innerInvoke(() => delegate.invoke(target, callback, applyThis, applyArgs, source));
|
|
28
28
|
},
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
onInvokeTask(delegate: ZoneDelegate, current: Zone, target: Zone, task: Task, applyThis: any, applyArgs: any) {
|
|
31
31
|
return self.innerInvoke(() => delegate.invokeTask(target, task, applyThis, applyArgs));
|
|
32
32
|
},
|
|
@@ -45,7 +45,7 @@ export class AsyncZone {
|
|
|
45
45
|
self._hasPendingMicrotasks = hasTaskState.microTask;
|
|
46
46
|
} else if (hasTaskState.change == 'macroTask') {
|
|
47
47
|
self._hasPendingMacrotasks = hasTaskState.macroTask;
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
if (hasTaskState.macroTask) {
|
|
50
50
|
if (!self._zonesWithPendingMacrotasks.includes(target))
|
|
51
51
|
self._zonesWithPendingMacrotasks.push(target);
|
|
@@ -56,7 +56,7 @@ export class AsyncZone {
|
|
|
56
56
|
|
|
57
57
|
self.checkStable();
|
|
58
58
|
},
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
onHandleError(delegate, current, target, error) {
|
|
61
61
|
self.runOutside(() => self._onError.next(error));
|
|
62
62
|
return false;
|
|
@@ -64,23 +64,23 @@ export class AsyncZone {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
private _zonesWithPendingMicrotasks
|
|
68
|
-
private _zonesWithPendingMacrotasks
|
|
67
|
+
private _zonesWithPendingMicrotasks: Zone[] = [];
|
|
68
|
+
private _zonesWithPendingMacrotasks: Zone[] = [];
|
|
69
69
|
|
|
70
|
-
private _outside
|
|
71
|
-
private _nesting
|
|
72
|
-
private _hasPendingMicrotasks
|
|
73
|
-
private _hasPendingMacrotasks
|
|
74
|
-
private _zone
|
|
75
|
-
private _onError
|
|
76
|
-
private _isStable
|
|
77
|
-
private _onMicrotaskEmpty
|
|
78
|
-
private _onStable
|
|
70
|
+
private _outside: Zone;
|
|
71
|
+
private _nesting: number = 0;
|
|
72
|
+
private _hasPendingMicrotasks = false;
|
|
73
|
+
private _hasPendingMacrotasks = false;
|
|
74
|
+
private _zone: Zone;
|
|
75
|
+
private _onError: Subject<Error> = new Subject<Error>();
|
|
76
|
+
private _isStable = false;
|
|
77
|
+
private _onMicrotaskEmpty: Subject<void> = new Subject<void>();
|
|
78
|
+
private _onStable: Subject<void> = new Subject<void>();
|
|
79
79
|
|
|
80
|
-
public static run<T>(cb
|
|
80
|
+
public static run<T>(cb: () => (Promise<T> | T)): Promise<T> {
|
|
81
81
|
return new Promise<T>((resolve, reject) => {
|
|
82
82
|
let zone = new AsyncZone('AsyncZone');
|
|
83
|
-
let value;
|
|
83
|
+
let value: T;
|
|
84
84
|
|
|
85
85
|
zone.onStable.subscribe(() => resolve(value));
|
|
86
86
|
zone.onError.subscribe(e => reject(e));
|
|
@@ -117,16 +117,16 @@ export class AsyncZone {
|
|
|
117
117
|
|
|
118
118
|
if (this._zonesWithPendingMicrotasks.length > 0 || this._zonesWithPendingMacrotasks.length > 0)
|
|
119
119
|
return;
|
|
120
|
-
|
|
120
|
+
|
|
121
121
|
try {
|
|
122
122
|
this._nesting++;
|
|
123
|
-
this._onMicrotaskEmpty.next(
|
|
123
|
+
this._onMicrotaskEmpty.next();
|
|
124
124
|
} finally {
|
|
125
125
|
this._nesting--;
|
|
126
126
|
|
|
127
127
|
if (!this._hasPendingMicrotasks) {
|
|
128
128
|
try {
|
|
129
|
-
this.runOutside(() => this._onStable.next(
|
|
129
|
+
this.runOutside(() => this._onStable.next());
|
|
130
130
|
} finally {
|
|
131
131
|
this._isStable = true;
|
|
132
132
|
}
|
|
@@ -134,15 +134,15 @@ export class AsyncZone {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
public runOutside(runnable) {
|
|
137
|
+
public runOutside(runnable: Function) {
|
|
138
138
|
this._outside.run(runnable);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
public invoke(callback
|
|
141
|
+
public invoke(callback: () => void) {
|
|
142
142
|
this._zone.runGuarded(() => this.innerInvoke(callback));
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
private innerInvoke(callback
|
|
145
|
+
private innerInvoke(callback: () => void) {
|
|
146
146
|
this.onEnter();
|
|
147
147
|
try {
|
|
148
148
|
return callback();
|
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/base64.test.ts","./src/base64.ts","./src/cache.test.ts","./src/cache.ts","./src/check-native-async.ts","./src/clone.test.ts","./src/clone.ts","./src/coalesce.test.ts","./src/coalesce.ts","./src/colors.ts","./src/console.ts","./src/constructor.ts","./src/decorators.ts","./src/environment.ts","./src/errors.test.ts","./src/errors.ts","./src/get-param-names.ts","./src/index.ts","./src/is-constructor.test.ts","./src/is-constructor.ts","./src/lazy-promise.ts","./src/lazy-subject.ts","./src/locks.test.ts","./src/locks.ts","./src/padding.ts","./src/presentation.test.ts","./src/presentation.ts","./src/serializer.ts","./src/test.ts","./src/time.ts","./src/timeout.ts","./src/zones.ts"],"version":"5.9.3"}
|
|
1
|
+
{"root":["./src/base64.test.ts","./src/base64.ts","./src/cache.test.ts","./src/cache.ts","./src/check-native-async.ts","./src/clone.test.ts","./src/clone.ts","./src/coalesce.test.ts","./src/coalesce.ts","./src/colors.ts","./src/console.ts","./src/constructor.ts","./src/decorators.ts","./src/environment.ts","./src/errors.test.ts","./src/errors.ts","./src/get-param-names.ts","./src/index.ts","./src/is-constructor.test.ts","./src/is-constructor.ts","./src/lazy-promise.ts","./src/lazy-subject.ts","./src/locks.test.ts","./src/locks.ts","./src/object-entries-typed.ts","./src/padding.ts","./src/presentation.test.ts","./src/presentation.ts","./src/serializer.ts","./src/test.ts","./src/time.ts","./src/timeout.ts","./src/zones.ts"],"version":"5.9.3"}
|