Fork me on GitHub
#clojurescript
<
2015-10-26
>
kurtlazarus08:10:10

Hey all, I’m currently using devcards from reagent’s lein template. I’m trying to include a function from a specific cljs file. However, for some reason, the function cannot be found. However, if I refer to other functions in the same file, clj doesn’t throw an excpetion.

kurtlazarus08:10:26

Has anybody ever experienced this?

kurtlazarus08:10:07

I’ve done lein clean.

kurtlazarus08:10:22

hmm, i suspect the files are getting cached

kurtlazarus08:10:40

old versions of files are getting cached that is

kurtlazarus08:10:24

Adding :devcards path to lein’s :clean-targets paths and then running lein clean does the trick.

razum2um09:10:20

@bhauman and anyone who needs figwheel + cljsbuild working inside your application system-map see https://github.com/bhauman/lein-figwheel/pull/266

abtv10:10:49

Could anyone give a piece of advice how to implement textarea with autoresize for Reagent application? I tried to use react-textarea-autosize component, but every time I type something it moves cursor position to the end of the component. Does anyone have ideas how to do it or what can be a problem?

bhauman12:10:36

@razum2um: I really wish you would have been in communication with me about this. This is a huge pull request and should be many small ones. I asked you to open an issue for discussion.

razum2um12:10:24

@bhauman: feel free to comment on any line, moreover, I think we should start to add tests to be sure, that it’s working, for now you can use my example app to get the idea and prove other things

razum2um12:10:50

@bhauman: I feel you started to move into right direction with that big refactor, but if I’m looking a bit into wrong direction - I’m ready to collaborate

bhauman12:10:33

yeah some discussion would be good

bhauman12:10:21

@razum2um: what time zone are you in?

abtv13:10:33

@rarous: What do I need to build it?

acron13:10:07

Anyone having trouble with cider-nrepl and figwheel today?

abtv13:10:08

@rarous: Do I need babel or something like this?

rarous13:10:29

@abtv i’ll create new gist with compiled version

acron13:10:38

(nevermind!)

abtv13:10:08

@rarous: thanks in advance!

ricardo13:10:43

So I think I’ve painted myself into a corner here with a Chrome extension I’m writing in ClojureScript.

ricardo13:10:07

This will be thinking out loud, in case anyone has any notes.

ricardo13:10:52

The extension has three major components. There’s the background page, which is doing processing on its own depending on events. Then there’s a display page, that can be used to show some information/settings. Then there’s supposed to be the content script.

ricardo13:10:00

The content script is executed when a page matching a pattern is loaded. The behavior I’m getting, however, is that after the ClojureScript code is injected, the page that had rendered just fine is now blank (view-source still returns the expected value).

ricardo13:10:21

Haven’t delved too deeply into it yet, but I suspect it’s because the content script code is still coming from the main, unified .js, which has react in it (I use it for the UI on the display page). A test content script on a test project that does not reference react works as expected.

ricardo13:10:40

Not entirely sure how to approach this… maybe separate builds.

thheller13:10:49

@ricardo: just a guess, but are you using an optimization other than :none without a :main?

thheller13:10:11

you'll need 3 seperate builds and the content-script can't be :none since it must be a single file

thheller13:10:18

at least as far as I can tell

ricardo13:10:23

@thheller: I am using optimizations on :whitespace but I do have a :main - content script on the React-less extension works without : main too (just tested).

mcgivernsa14:10:23

what happens if you use just react.js as your content script?

ricardo14:10:33

@mcgivernsa: Let me try and report back.

ricardo14:10:52

@thheller: Yeah, that’s what I’m thinking.

ricardo14:10:37

@mcgivernsa: Found the culprit before I got to that.

ricardo14:10:04

@mcgivernsa: It was actually that this build I was testing included devcards, and it was them that were causing the page flash.

thheller14:10:18

@ricardo if you are not using :main there is a chance that files that aren't actually used are included in your build

ricardo14:10:41

React has been exonerated. Still need to split it, since I don’t need all that on the content script, but at least I can do it after testing this bit.

thheller14:10:46

I'd use :main just to be safe simple_smile

ricardo14:10:01

@thheller: I know, but this build does have a :main.

ricardo14:10:31

It just shouldn’t have had devcards, which trip page when they get initialized on the content script.

ricardo14:10:33

Thanks for the help guys.

thheller14:10:56

seems like you sorted it out by yourself simple_smile

ricardo14:10:36

Hey, rubberducking is a thing. simple_smile

ricardo14:10:56

Someone mentions the build settings, you check, they’re as expected… then you notice devcards.

kurtlazarus14:10:11

Has anybody successfully used devcards with re-frame? I ask because I am attempting to use devcards to demonstrate small, simple examples with re-frame. I ​thought​ I’d do this with via dependency injection. However, this is turning out a bit more difficult than I thought. (edited) For example, https://github.com/Day8/re-frame/blob/e803659a56c7cca574f2d9d88df79307a0e52581/src/re_frame/subs.cljs#L26 I’d like to be able to inject my own database if I need to. However, there’s no hooks (is that the right term?) for me to do so. I’d love to hear people’s ideas. Forking could be an option.

ricardo14:10:56

@kurtlazarus: What part is tripping you? The complete loop?

kurtlazarus14:10:33

Nah. I understand and have used re-frame in the past. What I’d like to do is be able to demonstrate parts of the loop in a card.

ricardo14:10:43

I’m using devcard and re-frame separately (different projects), but I was wondering how to show the components given that they get their data from the subscription.

ricardo14:10:05

My current, untried thinking is having some custom query function for the devcards, which return test data.

ricardo14:10:44

But haven’t gotten there yet.

kurtlazarus14:10:03

In the file I linked above - registrations are just maps of keys and their handler function. Subscriptions are just applying a handler function to a vector.

kurtlazarus14:10:28

So I don’t think it should be that difficult.

ricardo14:10:35

Thing is… you are already going to have a bunch of register-sub. It seems like one could just separate the component declaration from the subscription declaration, and just have test register-subs initialized with the devcards.

kurtlazarus16:10:52

@ricardo: I think one of the main sells for me about devcards is that I can pull bits of actual functionality from my code and document/test/play around with them. Hauman describes figcards as a visual repl that allows you to incrementally iterate on the pieces of code you’re writing. I would love to be able to do the same with re-frame.

kurtlazarus16:10:28

For everything else besides re-frame, this has worked exceedingly well.

nberger19:10:12

Any recommendation for tracking clojurescript errors in production? I'm thinking about yeller, airbrake, sentry, rollbar, etc... Positive and negative experience reports are very welcome simple_smile

bensu19:10:41

@nblumoe: @tcrayford: should answer this simple_smile

tel19:10:34

@kurtlazarus: I have a reimplementation of reframe that nixes all the global variables

tel19:10:14

I’ve been planning on integrating it with devcards at some point or another, I think it would work really well

kurtlazarus19:10:47

it wasn’t to hard was it? like, re-frame’s source code is simple (in a good way) and easy to read)

tel19:10:21

it’s a bit tricky and wasn’t going for compatibility

tel19:10:38

the major trick is that if you dependency inject in reagent you can’t do it with bindings

tel19:10:53

b/c re-render will occur in different dynamic contexts

tel19:10:11

so I’m passing the state reference through the React child context

tel19:10:38

I dunno, I’ve been considering open sourcing it for a while

nberger19:10:42

@bensu: thanks for pinging @tcrayford, I can imagine a big part of his report 😛. I'd love to hear him critizicing the other services, but don't expect that to happen

richiardiandrea19:10:44

that's great I always wondered if you could remove the global

tel19:10:08

it’s not quite in a good state for public consumption and its been a while since I’ve maintained an OS Clojure lib

tel19:10:24

but if there’s some interest I’m sure I could figure it out

tel19:10:40

and I’d certainly love ideas

kurtlazarus19:10:52

honestly, i don’t know what the solution is right now and obviously don’t understand enough of how reagent works and utilizes react under the hood - however, i feel like if bruce could develop a reagent plugin for devcards, re-frame isn’t too far off

kurtlazarus19:10:41

i mean, he’s able to throw in tiny bits of state into the cards and demonstrate their capability

kurtlazarus19:10:50

maybe it’s a good frame of reference, maybe not

richiardiandrea19:10:21

I think @bhauman added experimental reagent support a last week

tel19:10:25

there’s probably some hackier ways of solving it… and you could always just instantiate global application state and have the devcards all share it

kurtlazarus19:10:14

btw, this guy has an open pull request in re-frame: https://github.com/Day8/re-frame/pull/107

kurtlazarus19:10:22

He was talking about it earlier today.

kurtlazarus19:10:09

So it seems like a lot of different individuals have ideas for improvement - and, from what I gather, the two main devs who author the repo are busy atm (aren’t we all)

tel19:10:11

huh, interesting

kurtlazarus19:10:17

the comments in the pull request lead me to believe that they’re hesitant to immediately start accepting merge requests as they have a bunch of apps in production that utilize the library

tel19:10:02

I don’t understand how there wouldn’t still be bad global interactions with things like register-handler

tel19:10:32

like, it could isolate the core mechanism, but most re-frame code would still be compatible only with the globally referenced version

darwin19:10:00

@tel: you have to pass around “re-frame” instance, or write some helpers which know which re-frame instance to reference

darwin19:10:29

original re-frame has only one instance which lives as global vars

tel19:10:34

gotcha, yeah

tel20:10:15

so that would require writing your application to be reframe DI friendly, yeah?

kurtlazarus20:10:34

New library idea: re-frameable

tel20:10:59

the current defs won’t cut it because they assume that global context, I think?

darwin20:10:49

@tel: not necessarily, you can have two namespaces, each holding one set of helpers to talk one re-frame instance

darwin20:10:05

this is not possible with old reframe, because you can require it only once

tel20:10:09

ah, that’s a good trick

darwin20:10:43

but would be possible with my fork, while still using it the old way, just use proper namespace to talk to preferred re-frame instance

darwin20:10:45

with my fork, it is possible to run many re-frames in the same js context, each will have its own run loop, handlers and subscriptions, but of course when registering handlers, subscriptions and starting run loop, you need to reference proper re-frame instance

darwin20:10:52

@kurtlazarus: I still don’t fully understand what exactly do you want from re-frame to be usable in devcards, do you need isolated re-frame instance per devcard? so each devcard runs its own mini-app?

kurtlazarus20:10:10

yea, something like that

kurtlazarus20:10:28

basically, i want to iterate from a simple example to a complicated example with re-frame’s loops

kurtlazarus20:10:17

i think being able to iterate from simple to complicated, and seeing that feedback, is very useful

kurtlazarus20:10:48

it also would be nice to see what a dispatcher does in isolation - so you could set up different dbs and test them

kurtlazarus20:10:07

just like you would for unit tests, etc.

darwin20:10:12

my fork allows all that, for each devcard you setup a brand new pair of app-db and app-frame and start their run-loop

kurtlazarus20:10:32

that sounds awesome - i’m gonna check that out

darwin20:10:22

you can also implement event processing a different way, maybe show db evolution step-by-step by applying a sequence of events

kurtlazarus20:10:40

that also seems more extensible as well - i could add in middleware to different run loops

tel20:10:52

yeah, this is cool

tel20:10:20

I think if this had existed before I started working in cljs I would have used it instead of writing something on my own

kurtlazarus20:10:05

> In essence re-frame provides a transducer: state, event -> state.

darwin20:10:10

if you ever needed to track if/when reagent components are being updated by reagent/react, you can look here: https://github.com/darwin/plastic/blob/master/src/main/plastic/reagent/patch.cljs

kurtlazarus20:10:23

yea, i like that idea very much

darwin20:10:42

I swap reagents render queue with my own to do benchmarking and logging of updates to componets

kurtlazarus20:10:49

that’s an idea that CLJS & JS dev crews have been passing back and forth

reefersleep20:10:46

Does anyone know how to convert a char to an ascii number value in Clojurescript? In Clojure, (int \a) works fine, for example, but in ClojureScript, this produces 0 regardless of what the char is

reefersleep20:10:14

I found a solution: (.charCodeAt "StringOrCharIThinkBothAreActuallyStrings" 0) will convert the character at position 0 of the String

dnolen20:10:25

@reefersleep: that’s the right solution

dnolen20:10:32

there are no chars in ClojureScript

dnolen20:10:53

\a -> “a”

reefersleep20:10:30

An important lesson for me simple_smile

samumbach21:10:24

any thoughts on how to promote cljs compiler warning WARNING: Use of undeclared Var ... to an error?

samumbach21:10:33

just tried messing with [closure-warnings](https://github.com/clojure/clojurescript/wiki/Compiler-Options#closure-warnings), which can be promoted from warnings to errors

samumbach21:10:07

but :undeclared-var is a cljs warning originating from the cljs compiler (not a wrapper around a closure warning/error)

dnolen21:10:17

@samumbach: it's already possible to configure ClojureScript warnings to become errors

dnolen21:10:26

some tools expose this, like cljsbuild

samumbach21:10:41

@dnolen: are you talking about :warning-handlers?

dnolen21:10:55

I don’t know what it’s called I just know it exists

samumbach21:10:08

@dnolen: ok; I'll dig into that; just wanted to check in to see what the recommendations are

samumbach21:10:16

I'll report back in a bit

samumbach21:10:54

@dnolen: is throwing an exception the right way to bail out of the compiler? or is there some other function I should be using?

richiardiandrea22:10:36

sorry to barge in, I confirm you need binding [ana/*cljs-warning-handlers* [ function ] ...

richiardiandrea22:10:48

in my code the error is added in an atom and "summed up" to the result of eval-str

richiardiandrea22:10:17

to produce an error instead of success in case a warning is thrown

samumbach22:10:00

@richiardiandrea: are you throwing an exception to produce that error?

richiardiandrea22:10:24

nope because it is not my use case

richiardiandrea22:10:56

but you can, you just need to store the warning somehow because it will be handled in your warning handler

richiardiandrea22:10:12

and eval-str will produce another result...

samumbach22:10:14

@richiardiandrea: you mentioned "to produce an error instead of success in case a warning is thrown" - how are you producing an error?

dnolen22:10:30

@samumbach: yes you can do whatever you like in the handler

richiardiandrea22:10:37

in my case I have a callback and everything goes inside it

dnolen22:10:39

throwing will just blowup compilation

richiardiandrea22:10:55

but how you produce the error is application dependent

samumbach22:10:01

@dnolen: just wondered if there was a way that didn't generate the stacktraces

dnolen22:10:26

throwing w/o stacktraces?

dnolen22:10:42

it’s just a hook, we don’t care what or how anything happens in the hook

samumbach22:10:02

exiting compiler and returning failed status w/out stacktraces

dnolen22:10:18

you can do that yourself

dnolen22:10:32

print the cause, (System/exit …)

samumbach22:10:49

do I need to shutdown agents or similar?

dnolen22:10:08

not with (System/exit …)

dnolen22:10:26

unless there’s some of your own cleanup that you need to do

samumbach22:10:35

@richiardiandrea: you mentioned collecting messages into an atom? is there some hook you use to perform an action after the build is finished?

richiardiandrea22:10:51

mmm I use warning-handler and the call eval-str

richiardiandrea22:10:08

the result of the two is merged

richiardiandrea22:10:25

and if there is a warning I show an error in my UI

samumbach22:10:51

@dnolen: thanks; (System/exit 1) is probably a better fit for me than raising an exception

samumbach22:10:08

@richiardiandrea: I'm not familiar with eval-str; is that from cljs? clojure? leiningen?

richiardiandrea22:10:40

sorry, it is from cljs.js

richiardiandrea22:10:50

clojurscript core

richiardiandrea22:10:02

i mean clojurescript 😄

samumbach22:10:51

@richiardiandrea: ah, so you're somehow injecting the cljs compilation warnings into the .js output?

richiardiandrea22:10:47

it is simple, not rocket science trust me, it is just an entry in an atom and a common exit point for your functions

richiardiandrea22:10:15

but again, I don't know how you're handling stuff

samumbach22:10:00

I just need a lein cljsbuild process to fail and print the desired messages...

richiardiandrea22:10:35

ah, then it is easy

richiardiandrea22:10:11

because cljsbuild allows you to specify your warning handler if I am not wrong..

samumbach22:10:18

clj
(defproject foo "0.1.0-SNAPSHOT"
  ,,,
  :cljsbuild {:builds [{:id "dev"
                        ,,,
                        :warning-handlers [(fn [warning-type env extra]
                                             (if (#{:undeclared-var} warning-type)
                                               (let [msg (cljs.analyzer/error-message warning-type extra)]
                                                 (binding [*out* *err*]
                                                   (println (cljs.analyzer/message env (str "ERROR: " msg))))
                                                 (System/exit 1)))
                                             (#'cljs.analyzer/default-warning-handler warning-type env extra))]
                        }]})

richiardiandrea22:10:46

cool, does it work?

samumbach22:10:02

@richiardiandrea @dnolen thanks for all your help 😀

dnolen22:10:10

released Om 1.0.0-alpha10, only changes are more validations and React Native support