diff --git a/src/lib/api/api-debug.interceptor.ts b/src/lib/api/api-debug.interceptor.ts index 1f38f30ceae792d9e0b40d1099ab0e6710f1c90f..d8f9b8d275fa8933e3e7c1712f47dee76f000edd 100644 --- a/src/lib/api/api-debug.interceptor.ts +++ b/src/lib/api/api-debug.interceptor.ts @@ -29,7 +29,10 @@ export interface FinalizeDebugEvent { type: 'finalize'; } -export type DebugEvent = RequestDebugEvent | ResponseDebugEvent | FinalizeDebugEvent; +export type DebugEvent = + | RequestDebugEvent + | ResponseDebugEvent + | FinalizeDebugEvent; export class ApiDebugInterceptor implements HttpInterceptor { private readonly sink$ = new ReplaySubject<DebugEvent>(10); @@ -40,7 +43,10 @@ export class ApiDebugInterceptor implements HttpInterceptor { this.enabled = conf.debug; } - public intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { + public intercept( + request: HttpRequest<any>, + next: HttpHandler + ): Observable<HttpEvent<any>> { if (!this.enabled) { return next.handle(request); } diff --git a/src/lib/dump-panel.component.ts b/src/lib/dump-panel.component.ts index 2135f4866b9dfc2f3c429c56a6c991fde38bb429..2ff072558aae1a6c4d867d7a18432902fc48a0ee 100644 --- a/src/lib/dump-panel.component.ts +++ b/src/lib/dump-panel.component.ts @@ -20,7 +20,10 @@ export class DumpPanelComponent { public spyCount = 0; public apiCallCount = 0; - public constructor(public readonly debugState: DebugStateService, private readonly cd: ChangeDetectorRef) {} + public constructor( + public readonly debugState: DebugStateService, + private readonly cd: ChangeDetectorRef + ) {} public setWatchCount(count: number): void { this.watchCount = count; diff --git a/src/lib/dump-value.component.ts b/src/lib/dump-value.component.ts index 566507dfa6356f807cf7e26edd9739995d3d3bb7..81f3800bf9e1f81bc7a20b0438da112ce33a0dfc 100644 --- a/src/lib/dump-value.component.ts +++ b/src/lib/dump-value.component.ts @@ -36,7 +36,11 @@ export class DumpValueComponent { return this.expanded.has(path.join('§')); } - private createNode(value: any, data: PropertyPath = [], refs = new Map<any, number>()): TreeNode { + private createNode( + value: any, + data: PropertyPath = [], + refs = new Map<any, number>() + ): TreeNode { if (value === null) { return { label: 'null', data, leaf: true, styleClass: 'null' }; } @@ -51,17 +55,32 @@ export class DumpValueComponent { } if (typeof value === 'string') { - return { label: JSON.stringify(value), data, leaf: true, styleClass: 'string' }; + return { + label: JSON.stringify(value), + data, + leaf: true, + styleClass: 'string', + }; } if (typeof value === 'number') { - return { label: value.toString(), data, leaf: true, styleClass: 'number' }; + return { + label: value.toString(), + data, + leaf: true, + styleClass: 'number', + }; } const clazz = value.constructor.name; let ref = refs.get(value); if (ref) { - return { label: `${clazz} @${ref}`, data, leaf: true, styleClass: 'reference' }; + return { + label: `${clazz} @${ref}`, + data, + leaf: true, + styleClass: 'reference', + }; } ref = refs.size; @@ -75,7 +94,9 @@ export class DumpValueComponent { leaf: entries.length === 0, children: entries .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)) - .map(([key, item]) => this.createNode(item, [].concat(data, [key]), refs)), + .map(([key, item]) => + this.createNode(item, [].concat(data, [key]), refs) + ), styleClass: 'object', expanded: this.isExpanded(data), }; diff --git a/src/lib/rxjs/hooks.ts b/src/lib/rxjs/hooks.ts index 71edcc96f10682f55b111b6fd9d22c2c14f4ef02..27c6fd8e4ae95990aee9ec1604cb564f77ebfbe4 100644 --- a/src/lib/rxjs/hooks.ts +++ b/src/lib/rxjs/hooks.ts @@ -2,30 +2,37 @@ * Fonctions pour "patcher" les méthodes d'une classe. */ -type Hookable<K extends string | symbol, M extends (...args: any[]) => any> = { [X in K]: M }; +type Hookable<K extends string | symbol, M extends (...args: any[]) => any> = { + [X in K]: M +}; -function isHookable<K extends string | symbol, M extends (...args: any[]) => any>( - what: unknown, - key: K -): what is Hookable<K, M> { - return typeof what === 'object' && what !== null && key in what && typeof (what as any)[key] === 'function'; +function isHookable< + K extends string | symbol, + M extends (...args: any[]) => any +>(what: unknown, key: K): what is Hookable<K, M> { + return ( + typeof what === 'object' && + what !== null && + key in what && + typeof (what as any)[key] === 'function' + ); } /** * Installe un hook. */ -function installHook<T extends Hookable<K, M>, M extends (this: T, ...args: any[]) => void, K extends string | symbol>( - target: T, - name: K, - makeHook: (old: M) => M -): void { +function installHook< + T extends Hookable<K, M>, + M extends (this: T, ...args: any[]) => void, + K extends string | symbol +>(target: T, name: K, makeHook: (old: M) => M): void { if (!isHookable<K, M>(target, name)) { throw new Error(`cannot hook ${name} on ${target}`); } if (name === 'constructor') { throw new Error('cannot hook constructors'); } - target[name] = <T[K]> makeHook(target[name]); + target[name] = <T[K]>makeHook(target[name]); } /** @@ -39,7 +46,7 @@ export function hookBefore< T extends Hookable<K, M>, M extends (this: T, ...args: any[]) => void, K extends string | symbol - >(target: Hookable<K, M>, name: K, hook: M): void { +>(target: Hookable<K, M>, name: K, hook: M): void { installHook( target, name, @@ -62,7 +69,7 @@ export function hookAfter< T extends Hookable<K, M>, M extends (this: T, ...args: any[]) => void, K extends string | symbol - >(target: T, name: K, hook: M): void { +>(target: T, name: K, hook: M): void { installHook( target, name, @@ -85,7 +92,7 @@ export function hookFinally< T extends Hookable<K, M>, M extends (this: T, ...args: any[]) => void, K extends string | symbol - >(target: T, name: K, hook: M): void { +>(target: T, name: K, hook: M): void { installHook( target, name, diff --git a/src/lib/rxjs/lazy.observable.ts b/src/lib/rxjs/lazy.observable.ts index ffa4877c6b0ee9b34b44f4a4c873b71950dd9705..39e85cf78248bf66d3387f629fc0c7fd9efffd06 100644 --- a/src/lib/rxjs/lazy.observable.ts +++ b/src/lib/rxjs/lazy.observable.ts @@ -4,7 +4,9 @@ import { defer, Observable, ObservedValueOf } from 'rxjs'; * Un observable qui attend le premier abonnement pour fabriquer l'observable qui va vraiment être * utilisé. */ -export function lazy<O extends Observable<any>>(create: () => O): Observable<ObservedValueOf<O>> { +export function lazy<O extends Observable<any>>( + create: () => O +): Observable<ObservedValueOf<O>> { let obs: O | null = null; return defer(() => (obs !== null ? obs : (obs = create()))); } diff --git a/src/lib/rxjs/route-param.decorator.spec.ts b/src/lib/rxjs/route-param.decorator.spec.ts index 9e2cf0f2b59597a6d67fb649127555ec6cd7c2c7..9b3f0e3b630459571b90557309e50c9023eb119c 100644 --- a/src/lib/rxjs/route-param.decorator.spec.ts +++ b/src/lib/rxjs/route-param.decorator.spec.ts @@ -6,9 +6,15 @@ import { marbles } from 'rxjs-marbles'; import { QueryParam, RouteParam } from './route-param.decorator'; function testOne(decorator: any, mapProperty: string) { - function mockActivatedRoute(map$: Observable<ParamMap>, snapshot: any): ActivatedRoute { + function mockActivatedRoute( + map$: Observable<ParamMap>, + snapshot: any + ): ActivatedRoute { // tslint:disable-next-line:rxjs-finnish - return { [mapProperty]: map$, snapshot: { [mapProperty]: snapshot } } as any; + return { + [mapProperty]: map$, + snapshot: { [mapProperty]: snapshot }, + } as any; } class FakeComponent implements OnInit, OnDestroy { @@ -31,7 +37,9 @@ function testOne(decorator: any, mapProperty: string) { 'should subscribe to paramMap on init', marbles(m => { const map$ = m.cold(''); - const comp = new FakeComponent(mockActivatedRoute(map$, convertToParamMap({}))); + const comp = new FakeComponent( + mockActivatedRoute(map$, convertToParamMap({})) + ); comp.ngOnInit(); @@ -46,7 +54,9 @@ function testOne(decorator: any, mapProperty: string) { 'should unsubscribe from paramMap on destroy', marbles(m => { const map$ = m.cold(''); - const comp = new FakeComponent(mockActivatedRoute(map$, convertToParamMap({}))); + const comp = new FakeComponent( + mockActivatedRoute(map$, convertToParamMap({})) + ); comp.ngOnInit(); comp.ngOnDestroy(); @@ -69,7 +79,10 @@ function testOne(decorator: any, mapProperty: string) { const map$ = m.hot('--a--b-^-c--|', VALUES); const comp = new FakeComponent(mockActivatedRoute(map$, VALUES.b)); - m.expect(comp.getParam$()).toBeObservable('b-c--|', { b: 'bar', c: 'quz' }); + m.expect(comp.getParam$()).toBeObservable('b-c--|', { + b: 'bar', + c: 'quz', + }); comp.ngOnInit(); diff --git a/src/lib/rxjs/route-param.decorator.ts b/src/lib/rxjs/route-param.decorator.ts index d1c7b1a2a0fc07fbbb1a7b565f525c33c7344663..9cdad74eb073a19c67bb0f23025861cdfeadb664 100644 --- a/src/lib/rxjs/route-param.decorator.ts +++ b/src/lib/rxjs/route-param.decorator.ts @@ -22,9 +22,15 @@ function ParamFromMap<K extends 'paramMap' | 'queryParamMap'>( const observer: Observer<string> = (this as any)[property]; if (!route || !(mapName in route)) { - throw new Error(`this.${routeProperty.toString()} must contains an ActivatedRoute`); + throw new Error( + `this.${routeProperty.toString()} must contains an ActivatedRoute` + ); } - if (observer === null || !('next' in observer) || typeof observer.next !== 'function') { + if ( + observer === null || + !('next' in observer) || + typeof observer.next !== 'function' + ) { throw new Error(`this.${property.toString()} must implement Observer`); } @@ -33,7 +39,9 @@ function ParamFromMap<K extends 'paramMap' | 'queryParamMap'>( observer.next(snapshot.get(resolvedParam)); } - (this as any)[subscription] = route[mapName].pipe(map(p => p.get(resolvedParam))).subscribe(observer); + (this as any)[subscription] = route[mapName] + .pipe(map(p => p.get(resolvedParam))) + .subscribe(observer); }); hookFinally(prototype, 'ngOnDestroy', function() { @@ -50,7 +58,10 @@ function ParamFromMap<K extends 'paramMap' | 'queryParamMap'>( * @param {string|null} param Nom du paramètre. Par défaut égal au nom de la propriété minus le '$' final. * @param {string} routeProperty nom de la propriété du Component contenant l'ActivatedRoute. Par défaut 'route'. */ -export function RouteParam(param: string = null, routeProperty: string = 'route') { +export function RouteParam( + param: string = null, + routeProperty: string = 'route' +) { return ParamFromMap(param, routeProperty, 'paramMap'); } @@ -62,6 +73,9 @@ export function RouteParam(param: string = null, routeProperty: string = 'route' * @param {string|null} param Nom du paramètre. Par défaut égal au nom de la propriété minus le '$' final. * @param {string} routeProperty nom de la propriété du Component contenant l'ActivatedRoute. Par défaut 'route'. */ -export function QueryParam(param: string = null, routeProperty: string = 'route') { +export function QueryParam( + param: string = null, + routeProperty: string = 'route' +) { return ParamFromMap(param, routeProperty, 'queryParamMap'); } diff --git a/src/lib/rxjs/safe-combine-latest.observable.ts b/src/lib/rxjs/safe-combine-latest.observable.ts index ce17270c5873ab89ff2d38999343b7f3b813cb2d..128517a6a920e88b00221a88711da3499999372b 100644 --- a/src/lib/rxjs/safe-combine-latest.observable.ts +++ b/src/lib/rxjs/safe-combine-latest.observable.ts @@ -4,12 +4,16 @@ import { combineLatest, Observable, ObservableInput } from 'rxjs'; * Observable qui envoie un tableau vide et ne complète pas. */ // tslint:disable-next-line:rxjs-finnish -const EMPTY_ARRAY_OBSERVABLE: Observable<any[]> = new Observable(subscriber => subscriber.next([])); +const EMPTY_ARRAY_OBSERVABLE: Observable<any[]> = new Observable(subscriber => + subscriber.next([]) +); /** * Variante de combineLatest qui transmets un tableau vide si le tableau des entrées est vide. */ -export function safeCombineLatest<T>(inputs$: Array<ObservableInput<T>>): Observable<T[]> { +export function safeCombineLatest<T>( + inputs$: Array<ObservableInput<T>> +): Observable<T[]> { if (inputs$.length === 0) { return EMPTY_ARRAY_OBSERVABLE; } diff --git a/src/lib/rxjs/safe-fork-join.observable.ts b/src/lib/rxjs/safe-fork-join.observable.ts index e49d7fff549589a96df8ffdc10ba430402bde3cd..b9f3150e67e9babd68b387858b4a96bdbddfac3d 100644 --- a/src/lib/rxjs/safe-fork-join.observable.ts +++ b/src/lib/rxjs/safe-fork-join.observable.ts @@ -6,7 +6,9 @@ import { take } from 'rxjs/operators'; * - renvoie un tableau vide si le tableau d'entrée est vide. * - retourne uniquement la première valeure de chaque entrée. */ -export function safeForkJoin<T>(inputs$: Array<ObservableInput<T>>): Observable<T[]> { +export function safeForkJoin<T>( + inputs$: Array<ObservableInput<T>> +): Observable<T[]> { if (inputs$.length === 0) { return of([]); } diff --git a/src/lib/rxjs/select.operator.ts b/src/lib/rxjs/select.operator.ts index d68da51702c25ec39f48fd51ec2a571f3ea8f3a7..8ef0cce6369a32d631fc3452846cb4ba75541ecd 100644 --- a/src/lib/rxjs/select.operator.ts +++ b/src/lib/rxjs/select.operator.ts @@ -39,7 +39,10 @@ export function select<T, R, V extends any[]>( } const values = selectors.map(s => s(input)) as V; - if (state.status === 'OPEN' && state.values.every((v, i) => isSame(v, values[i]))) { + if ( + state.status === 'OPEN' && + state.values.every((v, i) => isSame(v, values[i])) + ) { subscriber.next(state.output); return; } diff --git a/src/lib/rxjs/spy.operator.ts b/src/lib/rxjs/spy.operator.ts index 5117d04f9c898c8125718b835765795e970c538c..bf3416dbf260e0e02c48c34909fe133bffb4295c 100644 --- a/src/lib/rxjs/spy.operator.ts +++ b/src/lib/rxjs/spy.operator.ts @@ -1,6 +1,11 @@ import { MonoTypeOperatorFunction, Observable, ReplaySubject } from 'rxjs'; -export type NotificationType = 'next' | 'error' | 'complete' | 'subscribed' | 'unsubscribed'; +export type NotificationType = + | 'next' + | 'error' + | 'complete' + | 'subscribed' + | 'unsubscribed'; export interface Notification { tag: string; @@ -15,7 +20,12 @@ const timeOrigin = Date.now(); export function spy<T>(tag = 'spy'): MonoTypeOperatorFunction<T> { function log(type: NotificationType, payload?: any) { - notifications$.next({ tag, type, payload, timestamp: Date.now() - timeOrigin }); + notifications$.next({ + tag, + type, + payload, + timestamp: Date.now() - timeOrigin, + }); } return (source$: Observable<T>): Observable<T> => diff --git a/src/lib/rxjs/subject-accessors.decorator.ts b/src/lib/rxjs/subject-accessors.decorator.ts index 3d178faeea89c8b23f0d9749107f4f7b4dfb52b8..743af701428381b9cc8f6b2cf2173dc01803d308 100644 --- a/src/lib/rxjs/subject-accessors.decorator.ts +++ b/src/lib/rxjs/subject-accessors.decorator.ts @@ -7,14 +7,18 @@ */ export function SubjectAccessors() { return (prototype: object, observablePropertyName: string | symbol): void => { - Object.defineProperty(prototype, getPlainPropertyName(observablePropertyName), { - get(): any { - return this[observablePropertyName].getValue(); - }, - set(value: any): void { - this[observablePropertyName].next(value); - }, - }); + Object.defineProperty( + prototype, + getPlainPropertyName(observablePropertyName), + { + get(): any { + return this[observablePropertyName].getValue(); + }, + set(value: any): void { + this[observablePropertyName].next(value); + }, + } + ); }; } @@ -25,11 +29,15 @@ export function SubjectAccessors() { */ export function SubjectSetter() { return (prototype: object, observablePropertyName: string | symbol): void => { - Object.defineProperty(prototype, getPlainPropertyName(observablePropertyName), { - set(value: any): void { - this[observablePropertyName].next(value); - }, - }); + Object.defineProperty( + prototype, + getPlainPropertyName(observablePropertyName), + { + set(value: any): void { + this[observablePropertyName].next(value); + }, + } + ); }; } diff --git a/src/lib/rxjs/subscribe-on-init.decorator.spec.ts b/src/lib/rxjs/subscribe-on-init.decorator.spec.ts index 152c1ff43f25ebb150fd41fe0b171725d886b19a..9a9183f2047419210abf507cbf9dadbb27f4eb2c 100644 --- a/src/lib/rxjs/subscribe-on-init.decorator.spec.ts +++ b/src/lib/rxjs/subscribe-on-init.decorator.spec.ts @@ -8,7 +8,8 @@ describe('@SubscribeOnInit', () => { const VALUES = { a: 'a' }; let scheduler: MarbleTestScheduler<string>; - class PropertyTestClass<T extends Observable<any>> implements OnInit, OnDestroy { + class PropertyTestClass<T extends Observable<any>> + implements OnInit, OnDestroy { @SubscribeOnInit() public readonly obs$: T; @@ -51,7 +52,10 @@ describe('@SubscribeOnInit', () => { obj1.ngOnInit(); obj2.ngOnInit(); scheduler.schedule(() => obj1.ngOnDestroy(), scheduler.createTime('--|')); - scheduler.schedule(() => obj2.ngOnDestroy(), scheduler.createTime('----|')); + scheduler.schedule( + () => obj2.ngOnDestroy(), + scheduler.createTime('----|') + ); expectSubscriptions(obj1.obs$.subscriptions).toBe('^--!'); expectSubscriptions(obj2.obs$.subscriptions).toBe('^----!'); diff --git a/src/lib/rxjs/subscribe-on-init.decorator.ts b/src/lib/rxjs/subscribe-on-init.decorator.ts index 344eb54411a4f976c9c1f49c0d55ca4ed7d5a4c5..e998ca5a76c8f0909839bc346849d16dfa008d88 100644 --- a/src/lib/rxjs/subscribe-on-init.decorator.ts +++ b/src/lib/rxjs/subscribe-on-init.decorator.ts @@ -9,8 +9,10 @@ interface AutoSubscribable extends OnInit, OnDestroy {} type ObjectKey = string | number | symbol; -type AutoSubscriber<Name extends ObjectKey> = AutoSubscribable & { [SUBSCRIPTION_KEY]: Subscription } & { - [K in Name]?: Observable<any> +type AutoSubscriber<Name extends ObjectKey> = AutoSubscribable & { + [SUBSCRIPTION_KEY]: Subscription; +} & { + [K in Name]?: Observable<any>; }; /** @@ -19,12 +21,17 @@ type AutoSubscriber<Name extends ObjectKey> = AutoSubscribable & { [SUBSCRIPTION * est géré dans ngOnDestroy(). */ export function SubscribeOnInit() { - return <Target extends AutoSubscribable, Name extends ObjectKey>(target: Target, name: Name): any => { + return <Target extends AutoSubscribable, Name extends ObjectKey>( + target: Target, + name: Name + ): any => { const prototype = (target as any) as AutoSubscriber<Name>; hookBefore(prototype, 'ngOnInit', function() { if (!(this as any)[SUBSCRIPTION_KEY]) { - (this as any)[SUBSCRIPTION_KEY] = new Subscription(() => delete (this as any)[SUBSCRIPTION_KEY]); + (this as any)[SUBSCRIPTION_KEY] = new Subscription( + () => delete (this as any)[SUBSCRIPTION_KEY] + ); } if ((this as any)[name]) { (this as any)[SUBSCRIPTION_KEY].add((this as any)[name].subscribe()); diff --git a/src/lib/rxjs/testing/marbles.spec.ts b/src/lib/rxjs/testing/marbles.spec.ts index a20df063885b194933769f8b5ac26fa599abfdcf..b2a240934a5bad41e5c611fe386253ac7ed72880 100644 --- a/src/lib/rxjs/testing/marbles.spec.ts +++ b/src/lib/rxjs/testing/marbles.spec.ts @@ -22,7 +22,10 @@ describe('MarbleFormatter', () => { }); describe('.formatMarbles()', () => { - function mkNotif<T = any>(frame: number, notification: Notification<T>): Event<T> { + function mkNotif<T = any>( + frame: number, + notification: Notification<T> + ): Event<T> { return { frame, notification }; } @@ -31,39 +34,54 @@ describe('MarbleFormatter', () => { }); it('should represented known value with its key', () => { - expect(formatter.formatMarbles([mkNotif(0, Notification.createNext({ x: 'A' }))])).toEqual('a'); + expect( + formatter.formatMarbles([ + mkNotif(0, Notification.createNext({ x: 'A' })), + ]) + ).toEqual('a'); }); it('should represent values as "o" when no values are specified', () => { expect( formatter .withValues() - .formatMarbles([mkNotif(0, Notification.createNext('foo')), mkNotif(10, Notification.createNext('bar'))]) + .formatMarbles([ + mkNotif(0, Notification.createNext('foo')), + mkNotif(10, Notification.createNext('bar')), + ]) ).toEqual('oo'); }); it('should throw on unexpected value', () => { - expect(() => formatter.formatMarbles([mkNotif(10, Notification.createNext('foo'))])).toThrow( - new Error('Unexpected value at 10 ms: "foo"') - ); + expect(() => + formatter.formatMarbles([mkNotif(10, Notification.createNext('foo'))]) + ).toThrow(new Error('Unexpected value at 10 ms: "foo"')); }); it('should represent complete as "|"', () => { - expect(formatter.formatMarbles([mkNotif(0, Notification.createComplete())])).toEqual('|'); + expect( + formatter.formatMarbles([mkNotif(0, Notification.createComplete())]) + ).toEqual('|'); }); it('should represent errors as "#" when no error is specified', () => { - expect(formatter.withError().formatMarbles([mkNotif(0, Notification.createError('foo'))])).toEqual('#'); + expect( + formatter + .withError() + .formatMarbles([mkNotif(0, Notification.createError('foo'))]) + ).toEqual('#'); }); it('should represent expected error as "#"', () => { - expect(formatter.formatMarbles([mkNotif(0, Notification.createError('error'))])).toEqual('#'); + expect( + formatter.formatMarbles([mkNotif(0, Notification.createError('error'))]) + ).toEqual('#'); }); it('should throw on unexpected error', () => { - expect(() => formatter.formatMarbles([mkNotif(10, Notification.createError('foo'))])).toThrow( - new Error('Unexpected error at 10 ms: "foo"') - ); + expect(() => + formatter.formatMarbles([mkNotif(10, Notification.createError('foo'))]) + ).toThrow(new Error('Unexpected error at 10 ms: "foo"')); }); it('should represent empty time frames as "-"', () => { @@ -104,7 +122,10 @@ describe('MarbleFormatter', () => { '-a--#', '--(a|)', ].forEach(marbles => { - TEST_CASES.push([marbles, TestScheduler.parseMarbles(marbles, VALUES, ERROR, false, true)]); + TEST_CASES.push([ + marbles, + TestScheduler.parseMarbles(marbles, VALUES, ERROR, false, true), + ]); }); for (const [marbles, messages] of TEST_CASES) { @@ -118,19 +139,29 @@ describe('MarbleFormatter', () => { describe('formatSubscriptions', () => { it('should format empty subscriptions', () => { - expect(formatter.formatSubscriptions(new SubscriptionLog(Number.POSITIVE_INFINITY))).toEqual(''); + expect( + formatter.formatSubscriptions( + new SubscriptionLog(Number.POSITIVE_INFINITY) + ) + ).toEqual(''); }); it('should format closed subscription', () => { - expect(formatter.formatSubscriptions(new SubscriptionLog(10, 30))).toEqual(' ^-!'); + expect( + formatter.formatSubscriptions(new SubscriptionLog(10, 30)) + ).toEqual(' ^-!'); }); it('should format open subscription', () => { - expect(formatter.formatSubscriptions(new SubscriptionLog(10))).toEqual(' ^'); + expect(formatter.formatSubscriptions(new SubscriptionLog(10))).toEqual( + ' ^' + ); }); it('should format zero-duration subscription', () => { - expect(formatter.formatSubscriptions(new SubscriptionLog(10, 10))).toEqual(' (^!)'); + expect( + formatter.formatSubscriptions(new SubscriptionLog(10, 10)) + ).toEqual(' (^!)'); }); }); }); diff --git a/src/lib/rxjs/testing/marbles.ts b/src/lib/rxjs/testing/marbles.ts index bad7cfd7242ce57fa8537411026aea3d759559f8..421b3525a40e5a985d0c53ff33b94f26dab49020 100644 --- a/src/lib/rxjs/testing/marbles.ts +++ b/src/lib/rxjs/testing/marbles.ts @@ -7,7 +7,10 @@ import { Notification, Observable } from 'rxjs'; import { ColdObservable } from 'rxjs/internal/testing/ColdObservable'; import { HotObservable } from 'rxjs/internal/testing/HotObservable'; import { SubscriptionLog } from 'rxjs/internal/testing/SubscriptionLog'; -import { observableToBeFn, RunHelpers } from 'rxjs/internal/testing/TestScheduler'; +import { + observableToBeFn, + RunHelpers, +} from 'rxjs/internal/testing/TestScheduler'; import { TestScheduler } from 'rxjs/testing'; export interface Event<T> { @@ -52,16 +55,22 @@ export class MarbleFormatter<T = any> { event.notification.do( value => { - const key = this.values ? _.findKey(this.values, v => _.isEqual(value, v)) : 'o'; + const key = this.values + ? _.findKey(this.values, v => _.isEqual(value, v)) + : 'o'; if (!key) { - throw new Error(`Unexpected value at ${event.frame} ms: ${JSON.stringify(value)}`); + throw new Error( + `Unexpected value at ${event.frame} ms: ${JSON.stringify(value)}` + ); } group += key; }, error => { if (this.error !== undefined && !_.isEqual(error, this.error)) { const message = MarbleFormatter.errorMessage(error); - throw new Error(`Unexpected error at ${event.frame} ms: ${message}`); + throw new Error( + `Unexpected error at ${event.frame} ms: ${message}` + ); } group += '#'; }, @@ -81,7 +90,10 @@ export class MarbleFormatter<T = any> { return marbles; } - public formatSubscriptions({ subscribedFrame, unsubscribedFrame }: SubscriptionLog): string { + public formatSubscriptions({ + subscribedFrame, + unsubscribedFrame, + }: SubscriptionLog): string { if (subscribedFrame === Number.POSITIVE_INFINITY) { return ''; } @@ -94,7 +106,9 @@ export class MarbleFormatter<T = any> { marbles += '(^!)'; break; default: - marbles += `^${'-'.repeat((unsubscribedFrame - subscribedFrame) / this.frameDuration - 1)}!`; + marbles += `^${'-'.repeat( + (unsubscribedFrame - subscribedFrame) / this.frameDuration - 1 + )}!`; } return marbles; } @@ -111,7 +125,11 @@ export class MarbleFormatter<T = any> { } function isSubscriptionLog(data: any): data is SubscriptionLog { - return typeof data === 'object' && 'subscribedFrame' in data && 'unsubscribedFrame' in data; + return ( + typeof data === 'object' && + 'subscribedFrame' in data && + 'unsubscribedFrame' in data + ); } function isEvent<T>(data: any): data is Event<T> { @@ -131,7 +149,11 @@ export class MarbleTestScheduler<T> extends TestScheduler { return new MarbleTestScheduler<T>(this.formatter.withError(error)); } - public createColdObservable<X = T>(marbles: string, values?: Values<X>, error?: any): ColdObservable<X> { + public createColdObservable<X = T>( + marbles: string, + values?: Values<X>, + error?: any + ): ColdObservable<X> { return super.createColdObservable<X>( marbles, (values === undefined ? this.formatter.values : values) as Values<X>, @@ -139,7 +161,11 @@ export class MarbleTestScheduler<T> extends TestScheduler { ); } - public createHotObservable<X = T>(marbles: string, values?: Values<X>, error?: any): HotObservable<X> { + public createHotObservable<X = T>( + marbles: string, + values?: Values<X>, + error?: any + ): HotObservable<X> { return super.createHotObservable<X>( marbles, (values === undefined ? this.formatter.values : values) as Values<X>, @@ -166,20 +192,34 @@ export class MarbleTestScheduler<T> extends TestScheduler { return super.run(callback); } - private compare<U extends Event<T> | SubscriptionLog>(actual: U[], expected: U[]): void { + private compare<U extends Event<T> | SubscriptionLog>( + actual: U[], + expected: U[] + ): void { if ( (expected.length === 0 || isSubscriptionLog(expected[0])) && (actual.length === 0 || isSubscriptionLog(actual[0])) ) { - const expectedMarbles = expected.map(s => this.formatter.formatSubscriptions(s as SubscriptionLog)); - const actualMarbles = actual.map(s => this.formatter.formatSubscriptions(s as SubscriptionLog)); + const expectedMarbles = expected.map(s => + this.formatter.formatSubscriptions(s as SubscriptionLog) + ); + const actualMarbles = actual.map(s => + this.formatter.formatSubscriptions(s as SubscriptionLog) + ); expect(actualMarbles).toEqual(expectedMarbles); return; } - if ((expected.length === 0 || isEvent(expected[0])) && (actual.length === 0 || isEvent(actual[0]))) { - const expectedMarbles = this.formatter.formatMarbles(expected as Array<Event<T>>); - const actualMarbles = this.formatter.formatMarbles(actual as Array<Event<T>>); + if ( + (expected.length === 0 || isEvent(expected[0])) && + (actual.length === 0 || isEvent(actual[0])) + ) { + const expectedMarbles = this.formatter.formatMarbles(expected as Array< + Event<T> + >); + const actualMarbles = this.formatter.formatMarbles(actual as Array< + Event<T> + >); expect(actualMarbles).toEqual(expectedMarbles); return; } @@ -192,7 +232,9 @@ export class MarbleTestScheduler<T> extends TestScheduler { error?: any, frameDuration = this.frameTimeFactor ): MarbleTestScheduler<T> { - return new MarbleTestScheduler<T>(new MarbleFormatter<T>(values, error, frameDuration)); + return new MarbleTestScheduler<T>( + new MarbleFormatter<T>(values, error, frameDuration) + ); } } diff --git a/src/lib/rxjs/until-destroyed.operator.ts b/src/lib/rxjs/until-destroyed.operator.ts index b69bec20a4699556972d188c7f95465edc216161..0d32e8752d9f641ef80363cbc2587b4854b99643 100644 --- a/src/lib/rxjs/until-destroyed.operator.ts +++ b/src/lib/rxjs/until-destroyed.operator.ts @@ -24,7 +24,9 @@ const OPERATOR = Symbol.for('untilDestroyedOperator'); * public ngOnDestroy() {} * } */ -export function untilDestroyed<T>(target: OnDestroy): MonoTypeOperatorFunction<T> { +export function untilDestroyed<T>( + target: OnDestroy +): MonoTypeOperatorFunction<T> { if (OPERATOR in target) { return (target as any)[OPERATOR]; } diff --git a/src/lib/watch/watch-display.component.ts b/src/lib/watch/watch-display.component.ts index f7c132b519830f2ecc4024d07c3330b350fa90ed..c9a4730b7a1fab9836fe3266d2acc8f047913a12 100644 --- a/src/lib/watch/watch-display.component.ts +++ b/src/lib/watch/watch-display.component.ts @@ -8,7 +8,9 @@ import { WatchedValue, WatchService } from './watch.service'; templateUrl: './watch-display.component.html', }) export class WatchDisplayComponent { - public readonly values$ = this.watchService.values$.pipe(tap(values => this.countChanged.emit(values.length))); + public readonly values$ = this.watchService.values$.pipe( + tap(values => this.countChanged.emit(values.length)) + ); @Output() public countChanged = new EventEmitter<number>(); diff --git a/src/lib/watch/watch.component.ts b/src/lib/watch/watch.component.ts index 93b7861ccd624a5f3730e5bc27e74eedfdf62c7f..290c6e06377664f0ac8b01bcbc18f67a6ec53100 100644 --- a/src/lib/watch/watch.component.ts +++ b/src/lib/watch/watch.component.ts @@ -1,5 +1,10 @@ import { Component, Input, OnDestroy, OnInit } from '@angular/core'; -import { BehaviorSubject, combineLatest, ReplaySubject, Unsubscribable } from 'rxjs'; +import { + BehaviorSubject, + combineLatest, + ReplaySubject, + Unsubscribable, +} from 'rxjs'; import { distinctUntilChanged, map } from 'rxjs/operators'; import { WatchedValue, WatchService } from './watch.service'; diff --git a/src/lib/watch/watch.service.ts b/src/lib/watch/watch.service.ts index f80664b7a45009094b4e7d37e9265a89e0fdb983..d92042fde4f30e0a37461587b1e03ec985310031 100644 --- a/src/lib/watch/watch.service.ts +++ b/src/lib/watch/watch.service.ts @@ -14,7 +14,9 @@ export class WatchService { private readonly registry = new Set<Observable<WatchedValue>>(); private readonly registry$ = new BehaviorSubject(this.registry); - public readonly values$ = this.registry$.pipe(switchMap(valueSet => safeCombineLatest(Array.from(valueSet)))); + public readonly values$ = this.registry$.pipe( + switchMap(valueSet => safeCombineLatest(Array.from(valueSet))) + ); public register(value$: Observable<WatchedValue>): Unsubscribable { if (!this.registry.has(value$)) {