henningn commented on code in PR #6099:
URL: https://github.com/apache/myfaces-tobago/pull/6099#discussion_r2007059504


##########
tobago-example/tobago-example-demo/src/main/ts/demo-sidebar.ts:
##########
@@ -0,0 +1,333 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { html, render } from "lit-html";
+
+interface SectionNode {
+  id: string;
+  title: string;
+  level: number;
+  children: SectionNode[];
+}
+
+export class Sidebar extends HTMLElement {
+  private sectionTree: SectionNode[] = [];
+  private scrollThrottleTimeout?: number;
+  private resizeHandler = this.throttle(this.adjustFixedPosition.bind(this), 
100);
+
+  connectedCallback(): void {
+    // Build the section tree hierarchy

Review Comment:
   Noch einmal zu den Kommentaren: Hier beschreibt der Text ja quasi, was man 
auch am Funktionsnamen erkennen könnte. Deswegen ist "naming things" auch so 
wichtig.
   
   Beim connectedCallback kann man komplett auf Kommentare verzichten und es 
wäre sogar etwas leichter zu lesen, weil sich der Code nicht so auseinander 
zieht.
   
       this.buildSectionTree();
       this.renderContentTree();
       window.addEventListener("resize", this.resizeHandler);
       this.adjustFixedPosition();
       if (window.location.hash) {
         this.handleHashChange();
       }
       this.updateActiveSection();



##########
tobago-example/tobago-example-demo/src/main/ts/demo-sidebar.ts:
##########
@@ -0,0 +1,333 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { html, render } from "lit-html";
+
+interface SectionNode {
+  id: string;
+  title: string;
+  level: number;
+  children: SectionNode[];
+}
+
+export class Sidebar extends HTMLElement {
+  private sectionTree: SectionNode[] = [];
+  private scrollThrottleTimeout?: number;
+  private resizeHandler = this.throttle(this.adjustFixedPosition.bind(this), 
100);
+
+  connectedCallback(): void {
+    // Build the section tree hierarchy
+    this.buildSectionTree();
+
+    // Render the initial tree
+    this.renderContentTree();
+
+    // Add event listeners for page changes
+    window.addEventListener("resize", this.resizeHandler);
+
+    // Initial position adjustment
+    this.adjustFixedPosition();
+
+    // Initial scroll to hash if present with proper timing
+    if (window.location.hash) {
+      this.handleHashChange();
+    }
+
+    // Update active section in all cases
+    this.updateActiveSection();
+  }
+
+  disconnectedCallback(): void {
+    // Clean up event listeners
+    window.removeEventListener("resize", this.resizeHandler);
+
+    // Clear any pending timeouts
+    if (this.scrollThrottleTimeout !== null) {

Review Comment:
   Ich glaube, es reicht völlig aus, nur "clearTimeout" zu machen. Man muss ja 
gar nicht auf "null" abfragen und der Garbage Collector würde 
scrollThrottleTimeout frei machen, wenn die Sidebar-Klasse entfernt wird.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@myfaces.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to