module.exports = class { onCreate(input) { this.state = { story: input.story, modal: null, removed: false, } } open(modal) { this.state.modal = modal } close() { this.state.modal = null } updateStory(data) { this.state.story = Object.assign(Object.assign({}, this.state.story), data) } addChapter(chapter) { this.state.story.chapters.push(chapter) this.refreshStory() } moveChapter(chapter, data) { if (data.storyId !== this.state.story.id) { this.state.story = Object.assign({}, this.state.story, {chapters: this.state.story.chapters.filter(ch => ch.id !== chapter.id)}) } } updateChapter(id, data) { const index = this.state.story.chapters.findIndex(ch => ch.id === id) if (index === -1) { return } this.state.story.chapters[index] = Object.assign({}, this.state.story.chapters[index], data); this.refreshStory() } removeChapter(id) { const index = this.state.story.chapters.findIndex(ch => ch.id === id) if (index === -1) { return } this.state.story.chapters.splice(index, 1) this.refreshStory() } menuSelect(kind, id) { switch (kind) { case "add": this.open("chapter.add") break } } updateStoryTags(tags) { this.state.story.tags = tags this.refreshStory() } timeToDie() { this.state.removed = true } refreshStory() { this.state.story = Object.assign({}, this.state.story) } }