Fork me on GitHub
#clojurescript
<
2016-09-07
>
lxsameer09:09:12

hi, I'm using re-natal and re-frame to write an android app

lxsameer09:09:05

db is supposed to be a map in event handler but it's a promise in my case

lxsameer09:09:16

what's the problem

am-a_metail09:09:17

@lxsameer did the comment on github make sense to you? Did you check through your code?

lxsameer09:09:57

yeah my code is pretty basic. I just added the Linking event listener

am-a_metail09:09:21

I suggest maybe 1) #re-frame and 2) Maybe post the rest of your code for extra eyes

lxsameer09:09:34

@am-a_metail hmm the code i posted to github is exactly what i have beside the default re-natal's template

lxsameer09:09:45

@am-a_metail also can you please explain the github comment in a simpler language ? I'm not a native English person

am-a_metail10:09:58

I think the comment is saying that some other code is causing this error because it is not (assoc db :key val) but returning val instead

dimovich11:09:12

why isn't the result (cljs.core/println 1 2 3 4) ?

mac12:09:22

I think I am being bitten by laziness. Why would

(.nodesBetween pmed.doc.content 0 900 (fn [node path parent] (print node)))
print correctly to the cljs repl but
(.nodesBetween pmed.doc.content 0 900 (fn [node path parent] node))
just output nil at the repl? Is there a way to force evaluation?

keymone12:09:12

@mac what is .nodesBetween? what happens if you place node after (print node)? possibly .nodesBetween doesn’t return anything, only iterates.

rovanion12:09:00

Does anyone have any experience using figwheel with WebGL? I'm perhaps looking for the interaction react gives to the DOM but against the WebGL state machine instead.

agile_geek12:09:28

I'm with @keymone on this. .nodesBetween probably returns nil but (print node) is outputing node to REPL.

mac12:09:55

@keymone @agile_geek ...(print node) node)) produces the output and then nil. Was this what you meant?

keymone12:09:27

@mac yes, seems like .nodesBetween just doesn’t return anything

mac12:09:04

@keymone @agile_geek Ok, is there a way to usefully interact with it from cljs? if I wanted the values in a vector?

keymone12:09:34

@mac look for a function that does return objects. or use atom and swap! conj to collect nodes

mac12:09:33

@keymone @agile_geek Thanks, by look for you mean if the js library has a different function?

agile_geek12:09:58

@mac: yes or use a let to scope an atom containing the vector and use swap! conj to accumulate the nodes into vector before returning the dereferenced atom at end of let.

mac12:09:59

@agile_geek @keymone Thanks a lot. Is there any reason why `js->clj`` would return a #object ? This is not related to my other question.

agile_geek12:09:33

@mac something like htis (warning not tested in a REPL!):

(let [nodes (atom [])]
  (.nodesBetween pmed.doc.content 0 900 (fn [node path parent] (swap! nodes conj node)))
  @nodes)

dnolen12:09:55

@mac if the constructor/prototype isn’t exactly Object, we won’t touch it

mac12:09:26

@dnolen Ah so anything that inherits from something different than Object will not be converted?

keymone12:09:18

@dnolen i’m puzzled by this defmacro thing dimovich posted, do you know what is happening?

dnolen12:09:10

@keymone because macros take two “magic” initial arguments, env and form

keymone12:09:01

well that explains it

dnolen12:09:40

thinking more about it, the above should work - but I’ve been given no information where this is being tried

dnolen12:09:05

Planck? Figwheel, etc

dnolen12:09:16

so that’s the problem

dnolen12:09:30

you cannot use the bootstrap stuff to know what the actual behavior is

dnolen12:09:44

there’s tons of edge cases still needing sorting out there

dnolen12:09:29

@keymone and that particular REPL is probably a year out of date

keymone12:09:58

right.. will the recently released closure compiler for node help with cljs-bootstrap?

dnolen12:09:40

well only sort of - if you want to use advanced compilation with the generated JS from bootstrap

dnolen12:09:48

but you have a boatload of other problems to sort out beyond that

dnolen12:09:13

http://clojurescript.io, I believe this one is kept more up-to-date with ClojureScript changes

keymone12:09:40

good to know, thanks

dnolen12:09:00

still the only definitive thing is using non-bootstrap ClojureScript for now

mfikes13:09:05

@keymone You also can’t define and use a macro in the same compilation stage, which means you can’t do this in a REPL

keymone13:09:49

@mfikes is there a way to fake compilation stage in repl?

mfikes13:09:13

@keymone In self-hosted, you can play games with an internal implementation detail. It is described here http://blog.fikesfarm.com/posts/2015-09-07-messing-with-macros-at-the-repl.html

mfikes13:09:32

For your case, FWIW (in Planck):

cljs.user=> (ns foo.core$macros)
nil
foo.core$macros=> (defmacro m [& args]
             #_=> `(println [email protected]))
true
foo.core$macros=> (foo.core/m 1 2 3 4)
1 2 3 4
nil
foo.core$macros=> (m 1 2 3 4)
(cljs.core/println 3 4)

mfikes13:09:44

But, to really do this stuff properly, the m macro needs to go into a namespace in a file and you need to require-macros to load it into your REPL.

keymone13:09:03

@mfikes i’ll go through that as well, sounds fun 😃

hlolli14:09:40

@mfikes I was reading your article about eval in Planck, just curious to what the limitations are if any, compared to clj? Very nice I must way!

mfikes14:09:41

@hlolli The only corner case I’ve ever seen is described in https://github.com/mfikes/planck/issues/288

hlolli14:09:33

ok very nice. I have some clj projects I want to implement in cljs, since I do some metaprogramming, I would need eval. So these are good news.

nickt14:09:57

@mfikes that post on macros in the repl is extremely cool and so helpful, thank you

mfikes14:09:31

@nickt Glad it helped 🙂

mfikes14:09:20

@hlolli I haven’t thought about it in detail, but I suppose a ClojureScript lib could be created that essentially provides an eval for anyone who wants it (even JVM ClojureScript users), where that lib internally employs self-hosted ClojureScript to implement it.

dimovich14:09:38

where can I read more about repl's ? I'm using CIDER and boot and would like to read more about providing a repl from a running app, so I can inspect and try things while the application is running

hlolli14:09:03

that would be possible, I can imagine the jvm being able to compile self-hosted clojurescript, with jvm even becoming redundant. With self-hosted cljs I see noting stopping cljs becoming a full fledge lisp. But I don't see any problem using planck/eval for now.

dnolen15:09:33

@hlolli I’ve said it once and I’ll say it again. Self-hosted ClojureScript is always going to be a really awesome nice to have. It’s never ever ever going to be the main thing.

dnolen15:09:29

So anybody waiting for that, is going to be waiting a really long time 🙂

hlolli15:09:43

@dnolen I've heard you say that before some time ago, but lately I've been getting excited about the possibility of bootstraped core.async and possibly om.next. In the end we can always bootstrap JVM.js 😄 (joke).

dnolen15:09:21

bootstrapped is very powerful and I expect it to go many, many cool places

dnolen15:09:38

and making sure it always work will always be a priority as evident by the commit history

dnolen15:09:02

but eliminating the JVM from ClojureScript - never going to happen

nickt18:09:56

hey @darwin if you're around/not busy, this is what I've been working on the past week or so (the reason I kept bugging you with macro questions): https://github.com/nick-thompson/iss. It's pretty similar to https://github.com/noprompt/garden but has at least one pretty significant difference

nickt18:09:11

thanks again for your help. I'd be curious to hear what you think

darwin18:09:48

@nickt: I don’t have strong opinion about inline styles in general, I would have to study your readme and look at alternatives/current state of the art in more depth. I've used gaden a year ago, not for inline styles, but for composability when building my global app stylesheets: “css as data” is very powerful concept when coupled with rich set of data manipulation fns in clojure

darwin18:09:44

looking at https://github.com/nick-thompson/iss/blob/master/src/iss/macros.clj, I would propose to explore the eval usage in the inline fn, you would get general constant folding and allow clojure.core fns from it for free, additionaly you could make selected namespace like iss.constants visible to eval as well

darwin18:09:40

anyways, nice first step, I see, you’ve made nice progress

nickt18:09:22

@darwin definitely. Garden looks awesome and I intend to borrow some of the expressivity, but it doesn't offer the same kind of statically-analyzable output that enables stripping out style declarations from your js and building actual external stylesheets

nickt18:09:53

so far I haven't found an alternative that does... most of them dynamically insert <style> tags at runtime

nickt18:09:04

or use actual inline styles

nickt18:09:06

Also – that sounds awesome with eval, I'll totally give that some time. Still new to macros in general 😛

noprompt18:09:46

@nickt that looks interesting! i'll have to take a closer look soon. it's awesome that you're bringing this to the table. i've actually been in the process of working on the next release of garden (but i've mostly been keeping that to myself).

noprompt18:09:48

@darwin i should have an alpha ready within the next couple weeks of the next version of garden. it dramatically extends the CSS as data concept even further opening the door for programatic transformations of the underlying CSS AST.

noprompt19:09:59

i know it's been getting a little stale but i've been working in clojure much more and i really want this next version to check several boxes that are now open issues as well as provide more extensibility.

darwin19:09:59

@noprompt I’m glad to hear. Garden is great. Kudos! I would use it again, I just didn’t have CSS-heavy project on my hands lately.

noprompt19:09:15

the next version of garden includes a full blown CSS parser and unparser so raw CSS can be loaded and manipulated and used anywhere.

nickt19:09:25

^ that sounds awesome

nickt19:09:39

any chance you intend to make that happen at compile time?

noprompt19:09:32

so (css "h1,h2,h3 { font-weight: bold }") and (css [#{:h1 :h2, :h3} "font-weight: bold"]) are not only legal they're properly validated.

darwin19:09:11

an ultimate library would do as much work as possible at compile-time and delegate rest to runtime, but this can be pretty hard to implement it this way, when things get more complex

noprompt19:09:40

@nickt i'll look at that. i really want to get some of the core problems garden faces now addressed before moving on to more advanced optimizations.

nickt19:09:40

@darwin why would that be so hard?

nickt19:09:49

I think that'd be pretty doable

darwin19:09:00

doable yes, easy no

noprompt19:09:37

yeah, that's definitely not a weekend project. it's doable and easy to imagine but it's a lot of work.

noprompt19:09:56

i like those kinds of challenges though. 🙂

nickt19:09:58

I imagine you could do something like "for each declaration: (at macro time) attempt to inline declaration, if succeeds, extract, else write original back"

darwin19:09:48

have been working on a simple concept of (oget jsobj “key1” “key2”) to compile statically down to javascript jsobj[“key1”][“key2”] if possible, if not it would generate dynamic code

darwin19:09:01

and give you diagnostics/warnings in debug build

noprompt19:09:22

@nickt that might be a worthwhile library that could leverage the new stuff that's going to land in garden. since the new version of garden uses an intermediate representation, an ast in the clojure.xml format, you could combine that with something like enlive to do what you're talking about.

darwin19:09:54

basically you have to implement two code paths, one static in clojure and one dynamic in cljs: https://github.com/binaryage/cljs-oops/blob/f3768be97b2bdf387bf97e8fde15d2ef50a1aa8d/src/lib/oops/core.clj#L229-L233

noprompt19:09:59

so analyze the CSS AST and apply the styles to nodes which match in the HTML AST.

noprompt19:09:39

@darwin yeah. that technique can be tricky. sablano does the same kind of thing with it's compiler/interpreter namespaces.

nickt19:09:02

I'm not sure it needs to be that complicated even

nickt19:09:11

(re: analyze css ast and match it to html ast)

noprompt19:09:58

one thing i might be able to do, no promises, is have garden work against the CSSOM in the client. that actually has better performance (or it least it did a long time ago) than inline styles but i'd have to be sure that was still the case. i looked at that stuff a couple years ago and things are always improving.

nickt19:09:29

that would be pretty interesting

noprompt19:09:09

the hard part about it is that stylesheet objects are mutable and so you necessarily end up wanting to look at react style diff/patch operations which, for the majority of use cases, is not all that compelling. but in cases where you aren't using react it could be beneficial. i dunno, it seems like everyone is moving in the react-style direction so it's kind of low on my list of hip cool ideas i'd like to code up. 😄

noprompt19:09:15

speaking of react, has anyone written a pure clojurescript react-style renderer?

nickt19:09:14

that assumes that the mutability of stylesheet objects is a good idea

nickt19:09:07

or rather, that that mutability is something we should seek to preserve in solutions moving forward

shaun-mahood19:09:53

@noprompt: Are you expecting breaking changes in the next version of garden for the existing features?

noprompt19:09:46

@shaun-mahood i'm going to do my best to avoid breaking changes or, at least, provide a minimal path forward.

noprompt19:09:28

the only thing i've really changed with respect to syntax is how selectors are parsed. right now the selector part of a rule is written s1...sn the new syntax is s | [s1...sn] | #{ s | [s1..sn] }. the reason for the change is that the original approach of by taking the first n non-collection elements of the rule to be the selector makes it difficult to represent things like descendent selectors (now represented as [s1 s2 ... sn] (`s1 s2 .. sn`) and complex selectors #{[s1 s2] [s3 s4]} (`s1 s2, s3 s4`) as data. the selectors library was added to address that problem (and can still be used in the new version) but it can result in less than readable code, at least in my opinion.

noprompt19:09:44

i've also addressed the problem of writing raw css in garden. as i mentioned before garden will happily correctly parse a selector like "foo > bar, baz quux" just as if you'd written #{"foo > bar" [:baz :quux]} and won't break nesting.

noprompt19:09:30

that also applies to declarations the forms "border-bottom: 1px solid black", {:border-bottom "1px solid black"} and {:border-bottom [["1px" "solid" "black"]]} will all produce the same parse tree under the hood.

noprompt19:09:58

i don't think these modifications will break a lot of code and should require a minimal amount of updates. since i've included a parser for raw CSS it should be possible to provide a transitional parser which could get around the ambiguity when parsing a rule like [:h1 :h2 "font-weight: bold",,,] (since the parser could figure out that the selector is h1, h2).

noprompt19:09:25

garden's current parser is extremely dumb and will think "font-weight: bold" is a selector because it's not paranoid and totally believes in the benevolence of the programmer. 🙂

shaun-mahood20:09:24

@noprompt: Sound like good changes, worth it if something breaks (at least for me).