module.exports = class { onCreate(input) { this.state = { characters: input.characters, modal: null, } } open(modal) { this.state.modal = modal } close() { this.state.modal = null } characterRemoved({id}) { this.state.characters = this.state.characters.filter(c => c.id !== id) } characterEdited(character, patch) { const characters = this.state.characters.slice() const index = characters.findIndex(c => c.id === character.id) if (index === -1) { return } characters[index] = Object.assign(characters[index], patch) this.state.characters = characters } characterAdded(character) { this.state.characters = this.state.characters.concat(character) } characterNicksChanged(character, nicks) { const characters = this.state.characters.slice() const index = characters.findIndex(c => c.id === character.id) if (index === -1) { return } characters[index] = Object.assign(characters[index], {nicks: nicks.slice(), nick: (nicks[0] || "")}) this.state.characters = characters } }