(updater: (config: DB) => void)
| 1603 | |
| 1604 | async updateConfig(updater: (config: DB) => void): Promise<void> { |
| 1605 | this.writeQueue = this.writeQueue.then(async () => { |
| 1606 | const oldSnapshot: DB = JSON.parse(JSON.stringify(this.currentConfig)); |
| 1607 | updater(this.currentConfig); |
| 1608 | |
| 1609 | const hasChanged = |
| 1610 | JSON.stringify(oldSnapshot) !== JSON.stringify(this.currentConfig); |
| 1611 | |
| 1612 | if (!hasChanged) { |
| 1613 | return; |
| 1614 | } |
| 1615 | |
| 1616 | if (this.db) { |
| 1617 | this.db.data = { ...this.currentConfig }; |
| 1618 | await this.db.write(); |
| 1619 | } |
| 1620 | await this.notifyListeners(this.currentConfig); |
| 1621 | }); |
| 1622 | return this.writeQueue; |
| 1623 | } |
| 1624 | |
| 1625 | registerListener(listener: ConfigChangeListener): void { |
| 1626 | this.listeners.push(listener); |
| 1627 | } |
no test coverage detected