UNPKG

@ceramicnetwork/core

Version:

Typescript implementation of the Ceramic protocol

29 lines 890 B
import { Observable, Subscription } from 'rxjs'; import { StreamStateSubject, StreamUtils, } from '@ceramicnetwork/common'; export class StateLink extends Observable { constructor(initial, update$) { super((subscriber) => { const update$S = update$ ? update$(this.state$.value).subscribe(this.state$) : Subscription.EMPTY; this.state$.subscribe(subscriber).add(() => { update$S.unsubscribe(); }); }); this.initial = initial; this.state$ = new StreamStateSubject(initial); } next(state) { this.state$.next(state); } get state() { return this.state$.value; } get value() { return this.state$.value; } get id() { return StreamUtils.streamIdFromState(this.state); } } //# sourceMappingURL=state-link.js.map