mirror of
https://github.com/phfroidmont/scalive.git
synced 2025-12-25 21:46:59 +01:00
Support click events
This commit is contained in:
parent
1bd65fd49c
commit
124239925d
16 changed files with 277 additions and 162 deletions
|
|
@ -6,13 +6,13 @@ final case class MyModel(
|
|||
elems: List[Elem] = List.empty)
|
||||
final case class Elem(name: String, age: Int)
|
||||
|
||||
class TestView(initialModel: MyModel) extends LiveView[TestView.Cmd]:
|
||||
import TestView.Cmd.*
|
||||
class TestView(initialModel: MyModel) extends LiveView[String, TestView.Event]:
|
||||
import TestView.Event.*
|
||||
|
||||
private val modelVar = Var[MyModel](initialModel)
|
||||
|
||||
def handleCommand(cmd: TestView.Cmd): Unit =
|
||||
cmd match
|
||||
override def handleServerEvent(e: TestView.Event): Unit =
|
||||
e match
|
||||
case UpdateModel(f) => modelVar.update(f)
|
||||
|
||||
val el: HtmlElement =
|
||||
|
|
@ -33,5 +33,5 @@ class TestView(initialModel: MyModel) extends LiveView[TestView.Cmd]:
|
|||
)
|
||||
|
||||
object TestView:
|
||||
enum Cmd:
|
||||
enum Event:
|
||||
case UpdateModel(f: MyModel => MyModel)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue