From 710977f5b82ee13da49e678ed638f30b63a6caad Mon Sep 17 00:00:00 2001
From: Christoph Reiter <reiter.christoph@gmail.com>
Date: Tue, 2 Jun 2020 12:06:03 +0200
Subject: [PATCH] Add methods for when an activity gets added and removed
 (cleanup)

---
 packages/app-shell/src/app-shell.js | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/packages/app-shell/src/app-shell.js b/packages/app-shell/src/app-shell.js
index 4e10b848..91a1a217 100644
--- a/packages/app-shell/src/app-shell.js
+++ b/packages/app-shell/src/app-shell.js
@@ -626,24 +626,29 @@ export class AppShell extends ScopedElementsMixin(LitElement) {
             if (this._lastElm.tagName.toLowerCase() == activity.element.toLowerCase()) {
                 return this._lastElm;
             } else {
-                this._attrObserver.disconnect();
+                this._onActivityRemoved(this._lastElm);
                 this._lastElm = undefined;
             }
         }
 
         const elm = document.createElement(activity.element);
+        this._onActivityAdded(elm);
+        this._lastElm = elm;
+        return elm;
+    }
 
+    _onActivityAdded(element) {
         for(const key of this.topic.attributes || []) {
             let value = sessionStorage.getItem('vpu-attr-' + key);
             if (value !== null) {
-                elm.setAttribute(key, value);
+                element.setAttribute(key, value);
             }
         }
+        this._attrObserver.observe(element, {attributes: true, attributeFilter: this.topic.attributes});
+    }
 
-        this._attrObserver.observe(elm, {attributes: true, attributeFilter: this.topic.attributes});
-
-        this._lastElm = elm;
-        return elm;
+    _onActivityRemoved(element) {
+        this._attrObserver.disconnect();
     }
 
     _renderActivity() {
-- 
GitLab