module.exports = class { onCreate(input) { this.state = { channels: input.channels, modal: null, } } open(modal) { this.state.modal = modal } close() { this.state.modal = null } channelEdited(channel, patch) { const channels = this.state.channels.slice() const index = channels.findIndex(c => c.name === channel.name) if (index === -1) { return } channels[index] = Object.assign({}, channels[index], patch) this.state.channels = channels } channelAdded(channel) { this.state.channels = this.state.channels.concat(channel).sort((a,b) => a.name.localeCompare(b.name)) } }