### File

`src/lib/observable.data-source.ts`

### Extends

`BaseDataSource`

### Index

###### Properties
Protected _connectedViewer Protected _connectedViewerTeardown Protected Optional _data Protected _data$ Protected _lastRefreshed Protected _retry$ Protected _viewerIds Public Readonly change$ Public Readonly error$ Public Optional hasError Public Readonly hasError$ Public Optional loading Public loading$
###### Methods
Protected _connect Protected _disconnect Public attach Public connect Public derive Public disconnect Protected genericRetryFunction Public getViewerId Protected handelError Public isConnected Public refresh Public reset Public retry Public toJSON Public Async toPromise

### Constructor

`constructor(observable: Observable | null, metadata: ObservableDataSourceMetadata<Data> | null)`
Defined in src/lib/observable.data-source.ts:23
Parameters :
Name | Type | Optional
observable | `Observable<Data> | null` | No
metadata | `ObservableDataSourceMetadata<Data> | null` | No

### Methods

Protected _connect
`_connect(viewer: BaseDataSourceViewer)`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:323`
Parameters :
Name | Type | Optional
viewer | `BaseDataSourceViewer` | No
Returns : `| Observable`

Protected _disconnect
`_disconnect(viewerId: DataSourceViewerId)`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:308`
Parameters :
Name | Type | Optional
viewerId | `DataSourceViewerId` | No
Returns : `void`

Public attach
`attach(viewerId: DataSourceViewerId)`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:210`
Parameters :
Name | Type | Optional
viewerId | `DataSourceViewerId` | No
Returns : `Observable<Data>`

Public connect
`connect(viewerOrString: Viewer | DataSourceViewerId)`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:124`
Parameters :
Name | Type | Optional
viewerOrString | `Viewer | DataSourceViewerId` | No
Returns : `Observable<Data>`

Public derive
`derive(id: string, metadata: Partial<BaseDataSourceMetadata>)`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:270`
Parameters :
Name | Type | Optional | Default value
id | `string` | No |
metadata | `Partial<BaseDataSourceMetadata>` | No | `this.metadata`
Returns : `BaseDataSource<any>`

Public disconnect
`disconnect(viewerOrId: Viewer | DataSourceViewerId)`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:225`
Parameters :
Name | Type | Optional
viewerOrId | `Viewer | DataSourceViewerId` | No
Returns : `void`

Protected genericRetryFunction
`genericRetryFunction(error: any, retryCount: number)`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:311`
Parameters :
Name | Type | Optional
error | `any` | No
retryCount | `number` | No
Returns : `Observable<any>`

Public getViewerId
`getViewerId(viewer: Viewer)`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:114`
Parameters :
Name | Type | Optional
viewer | `Viewer` | No
Returns : `string`

Protected handelError
`handelError(error: any)`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:317`
Parameters :
Name | Type | Optional
error | `any` | No
Returns : `void`

Public isConnected
`isConnected(viewerOrId: Viewer | DataSourceViewerId)`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:217`
Parameters :
Name | Type | Optional
viewerOrId | `Viewer | DataSourceViewerId` | No
Returns : `boolean`

Public refresh
`refresh()`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:290`
Returns : `any`

Public reset
`reset()`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:297`
Returns : `any`

Public retry
`retry()`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:293`
Returns : `any`

Public toJSON
`toJSON()`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:280`
Returns : `object`

Public Async toPromise
`toPromise(viewer: Viewer)`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:264`
Creates a connection to tha data source and converts the Observable into a promise and then disconnects the viewer Parameters :
Name | Type | Optional
viewer | `Viewer` | No
Returns : `Promise<Data>`

### Properties

Protected _connectedViewer
Default value : `new Map<DataSourceViewerId, Observable<Data>>()`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:78`

Protected _connectedViewerTeardown
Default value : `new Map< DataSourceViewerId, TeardownLogic >()`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:79`

Protected Optional _data
Type : `Data`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:104`

Protected _data$
Type : `Observable<Data>`
Default value : `EMPTY`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:83`

Protected _lastRefreshed
Type : `Date | null`
Default value : `null`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:77`

Protected _retry$
Default value : `new Subject<void>()`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:90`

Protected _viewerIds
Default value : `new Map<Viewer, string>()`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:89`
a map of viewer to view id. Allows to create a view id from the viewer object reference

Public Readonly change$
Default value : `new Subject<Data>()`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:67`

Public Readonly error$
Default value : `new ReplaySubject<Error>(1)`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:73`

Public Optional hasError
Type : `Signal<boolean>`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:94`

Public Readonly hasError$
Default value : `new ToggleSubject()`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:72`

Public Optional loading
Type : `Signal<boolean>`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:92`

Public loading$
Type : `Observable<boolean>`
Default value : `EMPTY`
Inherited from `BaseDataSource`
Defined in `BaseDataSource:71`
Indicates weather the data source is currently loading new data

    import {
      Inject,
      Injectable,
      Optional,
    } from '@angular/core';
    import {
      BaseDataSource,
      BaseDataSourceMetadata,
      RxapDataSource,
    } from './base.data-source';
    import { Observable } from 'rxjs';
    import {
      RXAP_DATA_SOURCE_METADATA,
      RXAP_OBSERVABLE_DATA_SOURCE,
    } from './tokens';
    import { Constructor } from '@rxap/utilities';

    export interface ObservableDataSourceMetadata<Data> extends BaseDataSourceMetadata {
      data?: Observable<Data>;
    }

    @Injectable()
    export class ObservableDataSource<Data> extends BaseDataSource<Data, ObservableDataSourceMetadata<Data>> {

      constructor(
        @Optional() @Inject(RXAP_OBSERVABLE_DATA_SOURCE) observable: Observable<Data> | null,
        @Optional() @Inject(RXAP_DATA_SOURCE_METADATA) metadata: ObservableDataSourceMetadata<Data> | null = null,
      ) {
        super(metadata);
        if (observable) {
          this._data$ = observable;
        } else if (this.metadata.data) {
          this._data$ = this.metadata.data;
        }
      }

    }

    export function RxapObservableDataSource<Data>(
      metadata: ObservableDataSourceMetadata<Data>,
      className = 'ObservableDataSource',
      packageName = '@rxap/data-source',
    ) {
      return function (target: Constructor<ObservableDataSource<Data>>) {
        RxapDataSource(metadata, className, packageName)(target);
      };
    }

    export function observableDataSource<Data>(
      data: Observable<Data>,
      metadata: ObservableDataSourceMetadata<Data> = { id: 'static' },
    ): ObservableDataSource<Data> {
      return new ObservableDataSource(data, metadata);
    }

# results matching ""

# No results matching ""