@writetome51/observable-service
v4.0.0
Published
Abstract typescript/javascript class that acts as an abstraction layer between the class that creates an observable and the class that subscribes to that observable
Downloads
2
Maintainers
Readme
ObservableService<T>
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 6.1.x
and up.
Example
// Create a subclass...
export class UsersObservableService extends ObservableService<Users> {
constructor(
// an object with method that returns observable:
userQueryService: { getObservable: () => Subscribable<Users> }
) {
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
constructor(
__observableProvider: { getObservable: () => Subscribable<T> }
)
Methods
subscribe(observer): Unsubscribable
Installation
npm i @writetome51/observable-service
Loading
import { ObservableService } from '@writetome51/observable-service';