UNPKG

@river-build/sdk

Version:

For more details, visit the following resources:

37 lines 1.08 kB
import { Observable } from '../../../observable/observable'; export class TimelineEvents extends Observable { constructor(initialValue = []) { super(initialValue); } getLatestEvent(kind) { if (kind) { return this.value.find((event) => event.content?.kind === kind); } return this.value[this.value.length - 1]; } update(fn) { this.setValue(fn(this.value)); } reset() { this.setValue([]); } replace(newEvent, eventIndex, timeline) { const updated = [ ...timeline.slice(0, eventIndex), newEvent, ...timeline.slice(eventIndex + 1), ]; this.setValue(updated); } append(event) { this.setValue([...this.value, event]); } prepend(event) { this.setValue([event, ...this.value]); } removeByIndex(eventIndex) { const newEvents = this.value.slice(0, eventIndex).concat(this.value.slice(eventIndex + 1)); this.setValue(newEvents); } } //# sourceMappingURL=timelineEvents.js.map