From f9970858d46ce0518035889f9f7a3d38ff2f5ac9 Mon Sep 17 00:00:00 2001 From: BirDt_ Date: Sat, 11 Jul 2026 00:16:04 +0800 Subject: [PATCH] hackable with a repl --- app.scm | 62 ++++++++++++++++++++++++++++++++++++++++++++----- index.html | 9 +++++++ lib/mithril.scm | 7 ++++-- 3 files changed, 70 insertions(+), 8 deletions(-) diff --git a/app.scm b/app.scm index e595078..25694e7 100644 --- a/app.scm +++ b/app.scm @@ -1,13 +1,63 @@ (load "lib/mithril.scm") -(define click-count 0) +(define click-count + 0 + "Number of times the button has been clicked.") + +(define-macro (add-hook hook fn) + "(add-hook HOOK FN) + +Adds FN to HOOK." + `(set! ,hook (cons ,fn ,hook))) + +(define (run-hook hook) + "(run-hook HOOK) + +Runs all functions in HOOK." + (map + (lambda (fn) (fn)) + hook)) + +(define handle-click-hook + '() + "Hooks to run after the button is clicked.") + +(define (handle-click) + "(handle-click) + +The function that runs after the button is pressed. + +Increments `click-count', and runs `handle-click-hook'." + (set! click-count (+ 1 click-count)) + (run-hook handle-click-hook)) + +(define Heading + (component + (sxml + (h1 ~vnode.state.title)) + :title "LIPS! PWA!") + "The page heading component. + +Attributes: +* title: The title to display. + +__note__: Call (m.redraw) after attribute update.") (mount-root (component (sxml (main - (h1 "LIPS! PWA!") - (button (@ (onclick (lambda () - (set! click-count (+ 1 click-count)) - (print click-count)))) - ~(format "~a clicks" click-count)))))) + (Heading (@ (text "LIPS! PWA!"))) + (button (@ (onclick handle-click)) + ~(format "~a clicks" click-count)) + (div (@ (id "term"))) + (script + " +const term = terminal({ + selector: '#term', // you can use body for full screen terminal + dynamic: false, // dynamic scope, to have normal Scheme you should use false + name: 'demo', // name of the terminal if you want multiple REPL on same page + lips // LIPS namespace +}); +"))))) + diff --git a/index.html b/index.html index f589935..062ace3 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,15 @@ LIPS PWA + + + + + + + + diff --git a/lib/mithril.scm b/lib/mithril.scm index 7d15a5a..eae9858 100644 --- a/lib/mithril.scm +++ b/lib/mithril.scm @@ -5,7 +5,10 @@ document.body component)) -(define-macro (component view) +(define-macro (component view . args) + (when (= (remainder (length args) 2) 1) + (error "Component expected even length args.")) `(object :view - (lambda () (,@view)))) + (lambda (vnode) (,@view)) + ,@args))