I'm trying to do a very minimal example to get started using source / signal - based on some existing examples.
(1) Existing example: I'm getting guidance from an existing example called cselect.ur: https://github.com/urweb/urweb/blob/master/tests/cselect.ur fun main () = s <- source ""; return <xml><body> <cselect source={s} onchange={v <- get s; alert ("Now it's " ^ v)}> <coption>Wilbur</coption> <coption>Walbur</coption> </cselect> Hello, I'm <dyn signal={s <- signal s; return <xml>{[s]}</xml>}/>. I'll be your waiter for this evening. </body></xml> (2) Another existing example - the 'increment' demo: http://www.impredicative.com/ur/demo/increment.html (3) Initial coding attempt: I thought I could just make some minor modifications, to change the <cselect> in (1) to a <textbox>, as follows: fun main () = s <- source ""; return <xml><body> <textbox source={s} onchange={v <- get s; alert ("Now it's " ^ v)}> </textbox> Hello, I'm <dyn signal={s <- signal s; return <xml>{[s]}</xml>}/>. </body></xml> However, this is giving lots of compile errors. I don't understand the correct way to connect the source and the signal together, along with the controls on the page, plus the code inside the curly brackets { } . (4) Ultimately, what I want to develop is: (a) a <textbox> on the client, called `txbx`, which the user can change by typing (b) a table `t` on the server, which will be "live-queryable" using the <textbox>: (c) when user types something different in the <textbox>, there is an <xml> fragment below the <textbox> which instantly changes: eg - the <xml> fragment might be something like this: return queryX1 (SELECT Nam FROM t WHERE Nam LIKE '*' ^ {[txbx]} '*') (fn r => <xml>{[r.Nam]}<br/></xml>); I can't even get the simpler case (3) above to work. After I get (3) to work, then I can try (4). (5) Possibly elated work from 1998: Version 2.0 of a high-performance applicative / impredicative / functional columnar database called K from kx.com had a GUI which implemented something called "triggers" and "dependencies", similar to "sources" and "signals". The manual can still be read, via archive.org: http://web.archive.org/web/20050504070651/http://www.kx.com/technical/documents/kreflite.pdf Pages 35, 45 and 14 describe "dependencies" and "triggers" as used in the GUI: https://github.com/kevinlawler/kona/issues/304 The syntax in K was a bit more limited than Ur/Web's: Dependency: v..d: "b + c" means: if b or c changes, then update v to equal b + c Trigger: x..t: "pid 3: (`b; 0; :; x)" means: if x changes, then execute "pid 3: (`b; 0; :; x)" I think Ur/Web's source and signal syntax is more general than the syntax for dependencies and triggers in K from kx.com. However it can be interesting to compare this historical example of "dataflow". Meanwhile, due to the greater flexibility of Ur/Web's syntax, the programmer needs to take more care to correctly "wire" the pieces together. This is where I'm getting confused - the "dataflow wiring" in minimal example (3) above! Thanks for any help! ###
_______________________________________________ Ur mailing list [email protected] http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
