UNPKG

@ceramicnetwork/core

Version:

Typescript implementation of the Ceramic protocol

39 lines 1.16 kB
import { StreamStateSubject, SubscriptionSet } from '@ceramicnetwork/common'; import { StreamID } from '@ceramicnetwork/streamid'; export class RunningState extends StreamStateSubject { constructor(initial, pinned) { super(initial); this.subscriptionSet = new SubscriptionSet(); this._pinnedCommits = null; this.id = new StreamID(initial.type, initial.log[0].cid); if (pinned) { this.markAsPinned(); } } get tip() { return this.value.log[this.value.log.length - 1].cid; } get state() { return this.value; } get pinnedCommits() { return this._pinnedCommits; } get isPinned() { return this.pinnedCommits && this.pinnedCommits.size > 0; } add(subscription) { this.subscriptionSet.add(subscription); } complete() { this.subscriptionSet.unsubscribe(); super.complete(); } markAsPinned() { this._pinnedCommits = new Set(this.state.log.map(({ cid }) => cid.toString())); } markAsUnpinned() { this._pinnedCommits = null; } } //# sourceMappingURL=running-state.js.map