discourse/app/assets/javascripts/admin/addon/routes/admin-backups-index.js
Jarek Radosz 19214aff18
DEV: Clean up all message bus subscriptions (#19268)
1. "What Goes Up Must Come Down" – if you subscribe to message bus, make sure you also unsubscribe
2. When you unsubscribe - remove only your subscription, not **all** subscriptions on given channel

Attempt #2. The first attempt tried to extend a core `@bound` method in new-user-narrative plugin which did not work. I reworked that plugin in the meantime. This new PR also cleans up message bus subscriptions in now core-merged chat plugin.
2022-12-12 16:32:25 +01:00

28 lines
610 B
JavaScript

import Backup from "admin/models/backup";
import Route from "@ember/routing/route";
import { bind } from "discourse-common/utils/decorators";
export default Route.extend({
activate() {
this.messageBus.subscribe("/admin/backups", this.onMessage);
},
deactivate() {
this.messageBus.unsubscribe("/admin/backups", this.onMessage);
},
model() {
return Backup.find().then((backups) =>
backups.map((backup) => Backup.create(backup))
);
},
@bind
onMessage(backups) {
this.controller.set(
"model",
backups.map((backup) => Backup.create(backup))
);
},
});