Commands and subscriptions, and gui-update
gui-update is a plain function, so it cannot wait. It returns the work to do as values. A command is an (Event %m), synced in a fiber of its own, whose answer is the next message. A subscription is a source of messages that the model asks for: after each update the app starts the new ones and cancels the ones that are gone, by key. every sends a message on a timer, and subscription takes a source of one's own. The fibers belong to the app's scope and post their messages to the UI thread, so gui-update and view only run there. Closing the window cancels them. The prelude's path macros already use the name update, hence gui-update. 🤖 Generated with [ECA](https://eca.dev) (anthropic/claude-opus-4-8) Co-Authored-By: eca-agent <git@eca.dev>
This commit is contained in:
parent
2f4c99ba62
commit
4f48282314
6 changed files with 460 additions and 67 deletions
|
|
@ -8,7 +8,7 @@
|
|||
;;
|
||||
;; No window is opened. The test raises the events a user would cause on the
|
||||
;; Avalonia controls, and reads back what the controls hold, so it goes
|
||||
;; through the handlers, update, view and patch as a program does.
|
||||
;; through the handlers, gui-update, view and patch as a program does.
|
||||
|
||||
(import (std prelude))
|
||||
(import (std simpletest))
|
||||
|
|
@ -60,14 +60,15 @@
|
|||
(type (: Msg (Union Inc Dec (: Typed string) (: Shout bool) Reset)))
|
||||
(type (: Model (Record (: count int) (: name string) (: loud bool))))
|
||||
|
||||
(: update (-> Msg Model Model))
|
||||
(defun (update msg m)
|
||||
(match msg
|
||||
(Inc (record-set m (count (+ (.count m) 1))))
|
||||
(Dec (record-set m (count (- (.count m) 1))))
|
||||
((Typed s) (record-set m (name s)))
|
||||
((Shout b) (record-set m (loud b)))
|
||||
(Reset (Model (count 0) (name "") (loud #f)))))
|
||||
(: gui-update (-> Msg Model (Tuple Model (List (Event Msg)))))
|
||||
(defun (gui-update msg m)
|
||||
(next
|
||||
(match msg
|
||||
(Inc (record-set m (count (+ (.count m) 1))))
|
||||
(Dec (record-set m (count (- (.count m) 1))))
|
||||
((Typed s) (record-set m (name s)))
|
||||
((Shout b) (record-set m (loud b)))
|
||||
(Reset (Model (count 0) (name "") (loud #f))))))
|
||||
|
||||
(: greeting (-> Model string))
|
||||
(defun (greeting m)
|
||||
|
|
@ -92,7 +93,7 @@
|
|||
|
||||
(defun (main)
|
||||
(def/mutable roots 0)
|
||||
(def app (start-app (Model (count 0) (name "") (loud #f)) update view
|
||||
(def app (start-app (Model (count 0) (name "") (loud #f)) gui-update view
|
||||
(fun (c) (set! roots (+ roots 1)))))
|
||||
|
||||
(defun (at path) (app-control-at app path))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue