Fork me on GitHub
#clojurescript
<
2019-03-31
>
lspector01:03:37

Just learning about AppInventor/Thunkable, which is a whole new world to me, and I see that there's a way to include (I think) arbitrary Javascript: http://thunkableblocks.blogspot.com/2017/08/run-javascript-inside-web-viewer-with.html

lspector01:03:15

Anyone know what would be involved in using Clojurescript instead?

john16:03:07

@lspector using selfhosted cljs, you can make a reagent component that is a cljs editor for hiccup datastructure that creates another reagent component, which may also be an editor.

john16:03:00

I made something like that I called inception-component or something lol

john16:03:28

I'm not sure if I released anything but I have something of an example of it here https://pepl.io/admin

john16:03:22

the above component is rendered by the stuff in the editor below. Then below that are some more examples

john16:03:34

to get it to work, I think you'd have to clone my https://github.com/johnmn3/johnmn3 repo and then use your own auth info. But I didn't get around to testing it that far.

lspector16:03:01

@john I'm not sure I see how to take your advice re: my actual question, but https://pepl.io/admin is really cool! I will check that out regardless.

john16:03:10

maybe I don't actually understand this thunkable thing :thinking_face:

john16:03:00

and btw, I think the PEPL idea is pretty awesome, but most of the awesomeness of the inline editor comes from https://www.maria.cloud/

john16:03:07

@lspector wait, so this is a browser extension for automating browser interactions?

john16:03:06

and you want a chrome browser extension that will let you automate browser interactions with clojurescript?

john17:03:18

oh, I think I see what you mean... like, create a blockly language for clojurescript that could fit into that blockly language they're using there to integrate the javascript language

john17:03:57

Well, there's always https://github.com/roman01la/jsbin-cljs so if you can fetch a compiled version of that and call jsbin_cljs.core.eval on the source, you might be able to just do that

lspector17:03:00

I didn't mean creating a new blocky language. I meant using their blocky language and all of the infrastructure they created for it, but to be able to add new blocks that do custom computations, with the code for the new blocks being in Clojurescript (rather than Javascript).

dazld17:03:50

hey - I can’t seem to find how to consume a js iterator from cljs (eg new Map().entries) - how does this work?

valtteri18:03:00

@dazld

(def m (js/Map.))
(.set m 0 "kissa")
(.set m 1 "koira")

(def i (.entries m))
(.next i)
(.next i)

dazld18:03:18

the raw iterator interface is a bit clunky and stateful, as you demonstrate :I

dazld18:03:38

the experimental one in core seems to work great though

👍 4
valtteri18:03:57

True. That’s why it’s better stick to cljs data structures.

dazld18:03:11

well, it’s living in a js env..

dazld18:03:40

not first choice though

valtteri18:03:12

Google closure library might have some handy helper utils

zane18:03:47

What am I missing here?

⇒  clojure -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.520"}}}' -m cljs.main -e "(require 'cljs.js) (cljs.js/empty-state)"
Exception in thread "main" clojure.lang.ExceptionInfo: Execution error (Error) at (<cljs repl>:1).
Cannot read property 'empty_state' of undefined

zane18:03:42

By contrast:

⇒  clojure -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.520"}}}' -m cljs.main                                              
ClojureScript 1.10.520
cljs.user=> (require 'cljs.js)
nil
cljs.user=> (cljs.js/empty-state)
#object[cljs.core.Atom {…}]

zane18:03:45

I get the same error when I try the same thing via -m.

mfikes18:03:48

@U050CT4HR I think it is a race, owing to browser loads being async

zane18:03:45

Oh, that's interesting.

mfikes18:03:44

There is a potential fix in https://dev.clojure.org/jira/browse/CLJS-2854 that I'll re-baseline

mfikes18:03:19

CLJS-2854 actually just covers a different consequence of async loading.

maximtop19:03:50

Has anybody used chromex? How to setup environment in order to see source maps?

currentoor21:03:10

what’s the usual way, given an inst, to make a string like 1 minute ago or 3 months ago?

dazld21:03:49

convert to ms inst-ms, then use cond to find something like a duration that matches seconds, minutes, days, hours, whatever

dazld21:03:19

it’s a simple function

currentoor21:03:26

in principle yeah it’s simple but i don’t want to re-invent something that already exists

currentoor21:03:44

plus it needs to be human readable so have worry about plurals and stuff

currentoor21:03:51

this seems to work in cljs-time

currentoor21:03:56

[cljs-time.core :as time-core]
[cljs-time.format :as time-format]

(time-format/unparse-duration (time-core/interval
                                #inst "2018-03-31T21:43:15.786-00:00"
                                #inst "2019-03-31T21:43:15.786-00:00"))

martinklepsch11:04:59

Something similar exists in goog and is probably what cljs-time uses under the hood.

dpsutton21:03:47

i've achieved this with moment.js in the past: https://momentjs.com/docs/#/displaying/fromnow/

currentoor21:03:39

thanks, however i think i can get something similar from cljs-time

dpsutton21:03:26

oh? which ns. i'm not seeing anything like this

currentoor21:03:48

it’s not very well documented

currentoor21:03:49

[cljs-time.core :as time-core]
[cljs-time.format :as time-format]

(time-format/unparse-duration (time-core/interval
                                #inst "2018-03-31T21:43:15.786-00:00"
                                #inst "2019-03-31T21:43:15.786-00:00"))

currentoor21:03:48

and reading the source, this functionality is all built into goog.date.duration

💯 4
currentoor21:03:10

so you can just use that without needing to add cljs-time

dpsutton21:03:44

just was about to post that. didn't know about either of those