Setup eslint and enforce rules
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-06-02 22:36:25 -05:00
parent 82e7a1f299
commit 1d5056b753
149 changed files with 6104 additions and 3114 deletions

View File

@@ -62,18 +62,18 @@ export class BehaviorSubject<T> {
* True if this subject has been marked complete.
* @type boolean
*/
protected _isComplete: boolean = false
protected subjectIsComplete = false
/**
* The current value of this subject.
*/
protected _value?: T
protected currentValue?: T
/**
* True if any value has been pushed to this subject.
* @type boolean
*/
protected _hasPush: boolean = false
protected hasPush = false
/**
* Register a new subscription to this subject.
@@ -90,7 +90,7 @@ export class BehaviorSubject<T> {
return {
unsubscribe: () => {
this.subscribers = this.subscribers.filter(x => x !== subscriber)
}
},
}
}
@@ -110,9 +110,11 @@ export class BehaviorSubject<T> {
unsubscribe()
},
complete: (val?: T) => {
if ( typeof val !== 'undefined' ) resolve(val)
if ( typeof val !== 'undefined' ) {
resolve(val)
}
unsubscribe()
}
},
})
})
}
@@ -123,9 +125,11 @@ export class BehaviorSubject<T> {
* @return Promise<void>
*/
public async next(val: T): Promise<void> {
if ( this._isComplete ) throw new CompletedObservableError()
this._value = val
this._hasPush = true
if ( this.subjectIsComplete ) {
throw new CompletedObservableError()
}
this.currentValue = val
this.hasPush = true
for ( const subscriber of this.subscribers ) {
if ( subscriber.next ) {
try {
@@ -150,25 +154,32 @@ export class BehaviorSubject<T> {
* @return Promise<void>
*/
public async push(vals: T[]): Promise<void> {
if ( this._isComplete ) throw new CompletedObservableError()
if ( this.subjectIsComplete ) {
throw new CompletedObservableError()
}
await Promise.all(vals.map(val => this.next(val)))
}
/**
* Mark this subject as complete.
* The promise resolves when all subscribers have been pushed to.
* @param [final_val] - optionally, a final value to set
* @param [finalValue] - optionally, a final value to set
* @return Promise<void>
*/
public async complete(final_val?: T): Promise<void> {
if ( this._isComplete ) throw new CompletedObservableError()
if ( typeof final_val === 'undefined' ) final_val = this.value()
else this._value = final_val
public async complete(finalValue?: T): Promise<void> {
if ( this.subjectIsComplete ) {
throw new CompletedObservableError()
}
if ( typeof finalValue === 'undefined' ) {
finalValue = this.value()
} else {
this.currentValue = finalValue
}
for ( const subscriber of this.subscribers ) {
if ( subscriber.complete ) {
try {
await subscriber.complete(final_val)
await subscriber.complete(finalValue)
} catch (e) {
if ( subscriber.error ) {
await subscriber.error(e)
@@ -179,14 +190,14 @@ export class BehaviorSubject<T> {
}
}
this._isComplete = true
this.subjectIsComplete = true
}
/**
* Get the current value of this subject.
*/
public value(): T | undefined {
return this._value
return this.currentValue
}
/**
@@ -194,6 +205,6 @@ export class BehaviorSubject<T> {
* @return boolean
*/
public isComplete(): boolean {
return this._isComplete
return this.subjectIsComplete
}
}