import { noop } from '@cotto/utils.ts' export interface Observable { subscribe(subscriber: Subscriber): Subscription } export type PartialObservable = { [K in keyof T]?: T[K] | Observable } export interface Subscriber { next(value: T): void error(err: any): void complete(): void } export interface Subscription { unsubscribe: Function } export interface Subject extends Observable { next(value: T): void } export function isObs>(x: T | any): x is T { return x != undefined && (typeof x.subscribe === 'function') } export function isSubject>(x: T | any): x is T { return x != undefined && (typeof x.next === 'function') } export function subscribe(obs: Observable, next: ((x: T) => void) | Subscriber): Subscription { next = typeof next === 'function' ? { next, error: console.error, complete: noop } : next return obs.subscribe(next) } export function unsubscribe(subscription: Subscription) { return subscription.unsubscribe() }