Views, events as messages, and a patch, over plain Avalonia
A program is a model, an update and a view. A view is a Bjolang value; an event finds its message in the view its control was last given, and the next view is compared with the last so only what differs is changed. Controls are made with plain constructors and changed with SetValue, so nothing is subclassed, and a program never names an Avalonia type. Text, button, text input, checkbox, column and row. tests/app.bjo drives an app through its real controls with no window. 🤖 Generated with [ECA](https://eca.dev) (anthropic/claude-opus-4-8) Co-Authored-By: eca-agent <git@eca.dev>
This commit is contained in:
commit
2f4c99ba62
9 changed files with 1415 additions and 0 deletions
34
examples/counter.bjo
Normal file
34
examples/counter.bjo
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
;; bjogui/examples/counter.bjo — a counter and a greeting in a window.
|
||||
;;
|
||||
;; bjo run examples/counter.bjo
|
||||
|
||||
(import (std prelude))
|
||||
(import (bjogui view))
|
||||
(import (bjogui app))
|
||||
|
||||
(type (: Msg (Union Inc Dec (: Typed string))))
|
||||
(type (: Model (Record (: count int) (: name string))))
|
||||
|
||||
(: 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)))))
|
||||
|
||||
(: view (-> Model (View Msg)))
|
||||
(defun (view m)
|
||||
(column #:spacing 8.0 #:margin 16.0
|
||||
(text-input (.name m) Typed #:placeholder "Your name")
|
||||
(text #"Hello, ${(if (string-empty? (.name m)) "stranger" (.name m))}!" #:size 18.0)
|
||||
(row #:spacing 8.0
|
||||
(button "-" Dec #:width 40.0)
|
||||
(text #"${(.count m)}" #:size 18.0 #:margin 4.0)
|
||||
(button "+" Inc #:width 40.0))))
|
||||
|
||||
(defun (main)
|
||||
(run-app (Model (count 0) (name "")) update view #:title "Counter" #:width 320.0 #:height 200.0))
|
||||
Loading…
Add table
Add a link
Reference in a new issue