Loading packages/angular/data-source/accordion/src/lib/accordion.data-source.ts +4 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ import { OnDestroy, OnInit, } from '@angular/core'; import { toSignal } from '@angular/core/rxjs-interop'; import { BaseDataSource } from '@rxap/data-source'; import { Method } from '@rxap/pattern'; import { ToggleSubject } from '@rxap/rxjs'; Loading @@ -28,6 +29,9 @@ export abstract class AccordionDataSource< public override _data$ = new ReplaySubject<Data>(1); public override readonly loading$ = new ToggleSubject(true); public override readonly loading = toSignal(this.loading$, { initialValue: false }); public override readonly hasError = toSignal(this.hasError$, { initialValue: false }); protected parameters: Parameters | null = null; protected readonly _refresh$ = new Subject<void>(); Loading packages/angular/data-source/src/lib/base.data-source.spec.ts +48 −5 Original line number Diff line number Diff line import { fakeAsync } from '@angular/core/testing'; import { Injectable, InjectionToken, INJECTOR, Injector, runInInjectionContext, } from '@angular/core'; import { fakeAsync, TestBed, } from '@angular/core/testing'; import { run } from 'jest'; import { Subject } from 'rxjs'; import { BaseDataSource, Loading @@ -13,6 +24,10 @@ describe('@rxap/data-source', () => { it('connect and disconnect', () => { TestBed.configureTestingModule({}); const injector = TestBed.inject(INJECTOR); runInInjectionContext(injector,() => { const dataSource = new BaseDataSource<any>({ id: 'test', }); Loading @@ -26,6 +41,7 @@ describe('@rxap/data-source', () => { dataSource.disconnect(viewer); expect(dataSource.isConnected(viewer)).toBeFalsy(); }); }); Loading @@ -35,6 +51,7 @@ describe('@rxap/data-source', () => { id: 'test', restore: true, }) @Injectable() class TestDataSource extends BaseDataSource { protected override _data$ = new Subject(); Loading @@ -46,9 +63,21 @@ describe('@rxap/data-source', () => { } let dataSource: TestDataSource; let dataSourceB: TestDataSource; beforeEach(() => { dataSource = new TestDataSource(); const token = new InjectionToken<TestDataSource>('dataSourceB'); TestBed.configureTestingModule({ providers: [ TestDataSource, { provide: token, useClass: TestDataSource, } ] }); dataSource = TestBed.inject(TestDataSource); dataSourceB = TestBed.inject(token); localStorage.getItem('rxap_data-source_test'); }); Loading Loading @@ -103,7 +132,6 @@ describe('@rxap/data-source', () => { expect(spyA).toBeCalledWith(data); expect(localStorage.getItem('rxap_data-source_TestDataSource_test')).toBe(JSON.stringify(data)); const dataSourceB = new TestDataSource(); const spyB = jest.fn(); dataSourceB.connect({ id: 'test' }).subscribe(spyB); expect(spyB).toBeCalledWith(data); Loading @@ -120,7 +148,6 @@ describe('@rxap/data-source', () => { expect(spyA).toBeCalledWith(data); expect(localStorage.getItem('rxap_data-source_TestDataSource_test')).toBeNull(); const dataSourceB = new TestDataSource(); const spyB = jest.fn(); dataSourceB.connect({ id: 'test' }).subscribe(spyB); expect(spyB).not.toBeCalled(); Loading @@ -137,6 +164,8 @@ describe('@rxap/data-source', () => { let dataSource: StaticDataSource<string>; beforeEach(() => { TestBed.configureTestingModule({}); runInInjectionContext(TestBed.inject(INJECTOR), () => { dataSource = new StaticDataSource<string>( staticData, { Loading @@ -145,6 +174,7 @@ describe('@rxap/data-source', () => { }, ); }); }); it('should emit static data on subscribe', fakeAsync(() => { Loading Loading @@ -206,12 +236,24 @@ describe('@rxap/data-source', () => { }; @RxapDataSource(metadata) @Injectable() class DataSource extends BaseDataSource<any> { } let injector: Injector; beforeEach(() => { TestBed.configureTestingModule({ providers: [DataSource] }); injector = TestBed.inject(INJECTOR); }); it('should add meta data to base data source', () => { runInInjectionContext(injector, () => { expect(new DataSource().metadata).toEqual(metadata); }); }); Loading @@ -221,8 +263,9 @@ describe('@rxap/data-source', () => { id: 'custom', deps: [], }; runInInjectionContext(injector, () => { expect(new DataSource(customMetadata).metadata).toEqual(customMetadata); }); }); Loading packages/angular/data-source/src/lib/base.data-source.ts +2 −5 Original line number Diff line number Diff line Loading @@ -89,9 +89,9 @@ export class BaseDataSource< protected _viewerIds = new Map<Viewer, string>(); protected _retry$ = new Subject<void>(); public readonly loading: Signal<boolean>; public loading?: Signal<boolean>; public readonly hasError: Signal<boolean>; public hasError?: Signal<boolean>; constructor( @Optional() Loading @@ -99,9 +99,6 @@ export class BaseDataSource< metadata: Metadata | null = null, ) { super(metadata); // manuel initialize the members to ensure that all parent class properties are already set this.loading = toSignal(this.loading$, { initialValue: false }); this.hasError = toSignal(this.hasError$, { initialValue: false }); } protected _data?: Data; Loading Loading
packages/angular/data-source/accordion/src/lib/accordion.data-source.ts +4 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ import { OnDestroy, OnInit, } from '@angular/core'; import { toSignal } from '@angular/core/rxjs-interop'; import { BaseDataSource } from '@rxap/data-source'; import { Method } from '@rxap/pattern'; import { ToggleSubject } from '@rxap/rxjs'; Loading @@ -28,6 +29,9 @@ export abstract class AccordionDataSource< public override _data$ = new ReplaySubject<Data>(1); public override readonly loading$ = new ToggleSubject(true); public override readonly loading = toSignal(this.loading$, { initialValue: false }); public override readonly hasError = toSignal(this.hasError$, { initialValue: false }); protected parameters: Parameters | null = null; protected readonly _refresh$ = new Subject<void>(); Loading
packages/angular/data-source/src/lib/base.data-source.spec.ts +48 −5 Original line number Diff line number Diff line import { fakeAsync } from '@angular/core/testing'; import { Injectable, InjectionToken, INJECTOR, Injector, runInInjectionContext, } from '@angular/core'; import { fakeAsync, TestBed, } from '@angular/core/testing'; import { run } from 'jest'; import { Subject } from 'rxjs'; import { BaseDataSource, Loading @@ -13,6 +24,10 @@ describe('@rxap/data-source', () => { it('connect and disconnect', () => { TestBed.configureTestingModule({}); const injector = TestBed.inject(INJECTOR); runInInjectionContext(injector,() => { const dataSource = new BaseDataSource<any>({ id: 'test', }); Loading @@ -26,6 +41,7 @@ describe('@rxap/data-source', () => { dataSource.disconnect(viewer); expect(dataSource.isConnected(viewer)).toBeFalsy(); }); }); Loading @@ -35,6 +51,7 @@ describe('@rxap/data-source', () => { id: 'test', restore: true, }) @Injectable() class TestDataSource extends BaseDataSource { protected override _data$ = new Subject(); Loading @@ -46,9 +63,21 @@ describe('@rxap/data-source', () => { } let dataSource: TestDataSource; let dataSourceB: TestDataSource; beforeEach(() => { dataSource = new TestDataSource(); const token = new InjectionToken<TestDataSource>('dataSourceB'); TestBed.configureTestingModule({ providers: [ TestDataSource, { provide: token, useClass: TestDataSource, } ] }); dataSource = TestBed.inject(TestDataSource); dataSourceB = TestBed.inject(token); localStorage.getItem('rxap_data-source_test'); }); Loading Loading @@ -103,7 +132,6 @@ describe('@rxap/data-source', () => { expect(spyA).toBeCalledWith(data); expect(localStorage.getItem('rxap_data-source_TestDataSource_test')).toBe(JSON.stringify(data)); const dataSourceB = new TestDataSource(); const spyB = jest.fn(); dataSourceB.connect({ id: 'test' }).subscribe(spyB); expect(spyB).toBeCalledWith(data); Loading @@ -120,7 +148,6 @@ describe('@rxap/data-source', () => { expect(spyA).toBeCalledWith(data); expect(localStorage.getItem('rxap_data-source_TestDataSource_test')).toBeNull(); const dataSourceB = new TestDataSource(); const spyB = jest.fn(); dataSourceB.connect({ id: 'test' }).subscribe(spyB); expect(spyB).not.toBeCalled(); Loading @@ -137,6 +164,8 @@ describe('@rxap/data-source', () => { let dataSource: StaticDataSource<string>; beforeEach(() => { TestBed.configureTestingModule({}); runInInjectionContext(TestBed.inject(INJECTOR), () => { dataSource = new StaticDataSource<string>( staticData, { Loading @@ -145,6 +174,7 @@ describe('@rxap/data-source', () => { }, ); }); }); it('should emit static data on subscribe', fakeAsync(() => { Loading Loading @@ -206,12 +236,24 @@ describe('@rxap/data-source', () => { }; @RxapDataSource(metadata) @Injectable() class DataSource extends BaseDataSource<any> { } let injector: Injector; beforeEach(() => { TestBed.configureTestingModule({ providers: [DataSource] }); injector = TestBed.inject(INJECTOR); }); it('should add meta data to base data source', () => { runInInjectionContext(injector, () => { expect(new DataSource().metadata).toEqual(metadata); }); }); Loading @@ -221,8 +263,9 @@ describe('@rxap/data-source', () => { id: 'custom', deps: [], }; runInInjectionContext(injector, () => { expect(new DataSource(customMetadata).metadata).toEqual(customMetadata); }); }); Loading
packages/angular/data-source/src/lib/base.data-source.ts +2 −5 Original line number Diff line number Diff line Loading @@ -89,9 +89,9 @@ export class BaseDataSource< protected _viewerIds = new Map<Viewer, string>(); protected _retry$ = new Subject<void>(); public readonly loading: Signal<boolean>; public loading?: Signal<boolean>; public readonly hasError: Signal<boolean>; public hasError?: Signal<boolean>; constructor( @Optional() Loading @@ -99,9 +99,6 @@ export class BaseDataSource< metadata: Metadata | null = null, ) { super(metadata); // manuel initialize the members to ensure that all parent class properties are already set this.loading = toSignal(this.loading$, { initialValue: false }); this.hasError = toSignal(this.hasError$, { initialValue: false }); } protected _data?: Data; Loading