An open API service indexing awesome lists of open source software.

https://github.com/writetome51/observable-service

Abstract Typescript/JavaScript class that acts as a middleman between the class that creates the observable and the class that subscribes to the observable
https://github.com/writetome51/observable-service

javascript observable typescript

Last synced: 5 months ago
JSON representation

Abstract Typescript/JavaScript class that acts as a middleman between the class that creates the observable and the class that subscribes to the observable

Awesome Lists containing this project

README

          

# ObservableService\

An abstract TypeScript/JavaScript class which acts as an abstraction layer between
the provider of an observable and the class that subscribes to that observable.

NOTE: This version of ObservableService is intended for use with [RxJS](https://rxjs-dev.firebaseapp.com/) 6.1.x
and up.

## Example

view example

```ts
// Create a subclass...
export class UsersObservableService extends ObservableService {

constructor(
// an object with method that returns observable:
userQueryService: { getObservable: () => Subscribable }
) {
super(userQueryService);
}

}

// Now another class calls .subscribe() to access the data...
export class UsersSubscriptionService {

users: User[];
subscription: Subscription;

constructor(usersObservable: UsersObservableService) {
this.subscription = usersObservable.subscribe(
(users) => this.users = users
);
}

}
```

## Constructor
```ts
constructor(
__observableProvider: { getObservable: () => Subscribable }
)
```

## Methods

```ts
subscribe(observer): Unsubscribable
```

## Installation

`npm i @writetome51/observable-service`

## Loading
```js
import { ObservableService } from '@writetome51/observable-service';
```

## License
[MIT](https://choosealicense.com/licenses/mit/)