Fork me on GitHub
#hoplon
<
2016-05-20
>
lspector18:05:45

I'm still just getting started, experimenting with tweaks to the Get Started project (https://github.com/hoplon/hoplon/wiki/Get-Started). I want to add a text area to the web page, into which the user can type, and then grab that text in the function called when a button is pressed. I had thought from the name that an input cell would do that... but not the one used in the example... Is there a simple example of this in one of the demos, or can someone give me code or a pointer to help me do this?

alandipert19:05:29

@lspector: check out the todo list example on http://hoplon.io

alandipert19:05:47

it demonstrates the idiom of using an input cell in a closure

alandipert19:05:55

(last code example)

alandipert19:05:07

hm, with a textarea it's a little tricker, since textareas don't have a value attribute. their value is stored as a child text node

lspector20:05:24

@alandipert: Thanks. I think I could figure out how to adapt the todo example.... although the limitation to single line input would be pretty rough. Any pointers on how to circumvent this? FWIW the example that would solve all of my problems in one fell swoop (and help many others?) would have an input text area, a "process" button, and an output text area. The default function behind the process button could just put in the output area some simple transformation of the input, like the input up-cased or reversed. With this, folks like me who want to provide some (more interesting) input->output function, which we can write in Clojurescript, on the web, without knowing anything about web programming or Javascript, would be in business instantly.

alandipert20:05:49

sure, i can cook up an example quickly

lspector20:05:23

@alandipert: For even more generality/utility, it'd be great if the output area could be written to incrementally, in case the "process" function takes a long time to run and you want to provide status messages along the way.

alandipert21:05:41

@lspector: for that kinda thing i think you maybe want a separate status cell

alandipert21:05:07

the example i sent you runs process whenever the value of input changes

alandipert21:05:24

but if process takes a long time, you might want to use a watch instead... and leave cell world

alandipert21:05:28

the idea with javelin is that most UI updates are not cpu-heavy, just hard to orchestrate and do consistently

alandipert21:05:43

but you don't necessarily want to use them to do all kinds of processing

alandipert21:05:57

instead using them to build interfaces in front of other (potentially cpu/io heavy) processing

alandipert21:05:09

so that your UI is coupled to what your app does only indirectly, through cells

alandipert21:05:13

does that make sense?

lspector21:05:15

@alandipert: Woo hoo! And the separate status cell sounds right too. I can't try this right now (in a workshop...) but will as soon as I get a chance.

lspector21:05:46

@alandipert: I'm not sure that I do fully understand your comment about the concepts behind javelin and UI updates, but my "process" function will indeed almost always be CPU heavy (in a big way, sometimes).

alandipert21:05:34

have you ever done Swing stuff in java?

alandipert21:05:57

in like desktop UIs, one usually has at least 2 threads

alandipert21:05:01

1 to do the work, whatever it is

alandipert21:05:05

and 1 to do UI repaints

lspector21:05:05

What I mostly do is AI research...

alandipert21:05:41

if you try to use just 1 thread, the UI thread can block processing and vice versa, which is not what anyone usually wants

alandipert21:05:01

the browser environment is single-threaded, so to do work without blocking one needs to program with callbacks, which get queued kind of the way threads get scheduled

alandipert21:05:32

tl;dr it's not good to put functions that could block for a long time in formula cells, since that will block updates for any dependent UI bits

lspector21:05:34

But in that one thread, could I occasionally spit out some status to the status cell and have it actually appear in the browser while I keep computing?

alandipert21:05:49

well, there aren't threads really in the browser

alandipert21:05:00

there is something call a webworker, which is a limited form of thread and kind of weird to work with

alandipert21:05:20

but yeah that's the basic idea

alandipert21:05:39

this is how we do e.g. polling a server in most cases

lspector21:05:45

Hmm. What I want to do is conceptually like a single threaded program running in a terminal, which prints stuff out along the way while it does a long computation

alandipert21:05:24

and this computation is happening in the browser, not in the server?

dm321:05:26

for something compute-heavy that looks like Javelin you can look at http://docs.paralleluniverse.co/pulsar/ - the Dataflow part

alandipert21:05:49

i gotta run, but feel free to post on discourse if you have other q's

lspector21:05:15

Hmmm... from a quick look at pulsar I don't see how to get started with what I know, without learning a lot more. The lovely thing that attracted me to holon is the Get Started page that showed how to get a complete web page app up knowing only pure Clojure.

dm321:05:14

yeah, regrettably the browser isn't the best computing platform

lspector21:05:07

I think I'm going to try to stick with hoplon, ignore the issue about blocking, etc., and see how far I get

lspector21:05:49

Mainly just because it seems to me like it will be the easiest way, by far, to get something running in the users' browsers

lspector21:05:09

@alandipert: re: "and this computation is happening in the browser, not in the server?" Yeah, that's the idea. But again, just because I'm not a web programmer and don't know what I'm doing 🙂. The particular program I want to do this with is something that people could run in their terminals... except that my audience is mathematicians, many who won't know how to install anything on their computers... so since it's in Clojure, and since Clojurescript exists, I thought it'd be easiest to put something up that lets them run it in their browsers... and hoplon looks like it will let me do this without learning much of anything about web programming, assuming that I can handle the issues raised here (maybe I already can -- I have to study and try the code you posted :-).