import { Component, h, State } from '@stencil/core'; import { ClockControllerBase } from './clock-controller-base.js'; @Component({ tag: 'extends-controller-updates', }) export class ControllerUpdatesCmp extends ClockControllerBase { // Component owns the @State - not the base class @State() currentTime: string = new Date().toLocaleTimeString(); @State() isClockRunning: boolean = true; constructor() { super(); // No parameters needed } // Component implements the requestUpdate method (simulates Lit's this.host.requestUpdate()) protected requestUpdate(): void { // Controller calls this method to request a re-render // Component updates its own @State which triggers re-render this.currentTime = this.getCurrentTimeValue(); } toggleClock() { if (this.isClockRunning) { this.stopClock(); this.isClockRunning = false; } else { this.startClock(); this.isClockRunning = true; } } render() { return (

Controller-Initiated Updates Test

Clock Controller (requestUpdate Pattern)

Current Time: {this.currentTime}

How It Works

Clock Running: {this.isClockRunning ? 'Yes' : 'No'}

Base class calls requestUpdate() → Component updates @State → Re-render

Simulates Lit's this.host.requestUpdate() pattern

@State lives on component, controller requests updates

); } }