component_framework.components.counter
Simple counter component example.
1"""Simple counter component example.""" 2 3from ..core import Component, registry 4 5 6@registry.register("counter") 7class Counter(Component): 8 """A simple counter component.""" 9 10 template_name = "Counter" 11 12 def mount(self): 13 """Initialize counter to 0.""" 14 super().mount() 15 self.state["count"] = self.params.get("initial", 0) 16 17 def on_increment(self, amount: int = 1): 18 """Increment counter by amount.""" 19 self.state["count"] = self.state.get("count", 0) + amount 20 21 def on_decrement(self, amount: int = 1): 22 """Decrement counter by amount.""" 23 self.state["count"] = self.state.get("count", 0) - amount 24 25 def on_reset(self): 26 """Reset counter to 0.""" 27 self.state["count"] = 0
@registry.register('counter')
class
Counter7@registry.register("counter") 8class Counter(Component): 9 """A simple counter component.""" 10 11 template_name = "Counter" 12 13 def mount(self): 14 """Initialize counter to 0.""" 15 super().mount() 16 self.state["count"] = self.params.get("initial", 0) 17 18 def on_increment(self, amount: int = 1): 19 """Increment counter by amount.""" 20 self.state["count"] = self.state.get("count", 0) + amount 21 22 def on_decrement(self, amount: int = 1): 23 """Decrement counter by amount.""" 24 self.state["count"] = self.state.get("count", 0) - amount 25 26 def on_reset(self): 27 """Reset counter to 0.""" 28 self.state["count"] = 0
A simple counter component.
def
mount(self):
13 def mount(self): 14 """Initialize counter to 0.""" 15 super().mount() 16 self.state["count"] = self.params.get("initial", 0)
Initialize counter to 0.
def
on_increment(self, amount: int = 1):
18 def on_increment(self, amount: int = 1): 19 """Increment counter by amount.""" 20 self.state["count"] = self.state.get("count", 0) + amount
Increment counter by amount.