Fork me on GitHub
#clojurescript
<
2018-10-26
>
arthur01:10:08

I'm feeling dumb: in this code:

(defn ^:export mark-old-emails-read []
  (let [threads (js/GmailApp.search "older_than:10d label:unread \"github\" OR \"firebase\" OR \"3scale\" OR \"jira\" OR \"pagerduty\" OR \"Sentry\" OR filename:invite.ics OR \"Datadog\"")]
    (.log js/Logger (str "marking threads " threads))
    (doall (map (fn [thread]
                  (.-markRead thread)) ; <---- this line does nothing.
                threads))))
the call to .- does nothing

arthur01:10:23

i'm attempting to translate:

;; function MarkOldEmailsRead() {
     ;;   var threads = GmailApp.search('older_than:10d label:unread "github" OR "firebase" OR "3scale" OR "jira" OR "pagerduty" OR "Sentry" OR filename:invite.ics OR "Datadog"');
     ;;   threads.forEach(function(thread){
     ;;     thread.markRead();
     ;;   })
     ;; }
to clojurescript

arthur01:10:04

i think thread is nil ?

lilactown02:10:56

@arthur .- is for property access - do you mean to be calling a method?

arthur02:10:09

I'm trying to call the markRead method

arthur02:10:24

of the object that's a GmailThread

arthur02:10:30

not at all sure I'm doing it right

arthur02:10:02

@lilactown the equivelent of thread.markRead();

chrisulloa02:10:43

(.markRead thread) I think

arthur02:10:49

it was when i use .markRead it renames the call to .Zb

arthur02:10:03

TypeError: Cannot find function Zb in object GmailThread. (line 239, file "Code"

chrisulloa02:10:27

Is this after you compile/minify?

chrisulloa02:10:53

hmm I recall coming across this issue and making a note let me see if I can find it

arthur02:10:12

do i have to tell it not to mangle the name?

chrisulloa02:10:04

I had this issue accessing properties, (.-lngLat click) would not work since the the properties would get renamed, but (aget click "lngLat") worked

chrisulloa02:10:20

markRead is not a property though it's a method

arthur02:10:42

that's my understanding from the original JS code ^ there

arthur02:10:50

though i get such things wrong often

chrisulloa02:10:28

If it's a property try aget as I showed above

arthur02:10:51

would i get it, then call it?

chrisulloa02:10:24

Not sure about that one sorry, someone more experienced might chime in

arthur02:10:09

using aget returns nil

chrisulloa02:10:13

I think you need to define externs for this

chrisulloa02:10:22

To fix this problem, I had to add an extern for the external library method. Google Closure allows for the use of externs. Externs are files that declare the names of external libraries functions that should not be renamed. Google Closure provides extern files for some common libraries—in fact, the project that I was working on already included the jQuery extern, which is why I didn’t see any errors for the jQuery functions.

arthur02:10:22

i suspect that

chrisulloa02:10:36

I also suspect it's not good form to use aget to access properties of objects. So externs are probably better way to go. (use goog.object/get instead)

arthur02:10:01

i'm wishing there was a thing i could put right on that line saying don't mangle this. likely a naieve wish

chrisulloa02:10:56

externs are not terrible to deal with once you get them set up, luckily. good luck!

arthur02:10:13

i was trying to get this working for a demo at a meetup

arthur02:10:21

so were debugging with an audience

arthur02:10:01

kinda a group learning thing

chrisulloa02:10:35

You can avoid minifying if it's just to demo the code

simongray07:10:32

hey everyone! We have been using PhantomJS for running ClojureScript tests as part of our CI pipeline. We also use reagent on the frontend and upgrading it to the most recent version (from 0.7 to 0.8.1) means we get React 16+ as a dependency. The "problem" is that React 16+ is compiled to a more recent version of JavaScript than the one supported by PhantomJS, so suddenly we're not able to run any tests since our JS imports contain "invalid" JS syntax like Set and Map.

simongray07:10:43

What is a good drop-in replacement for PhantomJS?

statonjr12:10:44

We ran into a similar problem and used core-js to fill in those syntax holes: https://www.npmjs.com/package/core-js

statonjr12:10:24

On my current project, we dropped PhantomJS and are using geckodriver and chromedriver in headless mode.

simongray07:10:15

(PhantomJS development has been discontinued, unfortunately)

dvcrn08:10:03

Hey guys!I am trying to migrate one of my cljsbuild projects to the cli but have some problems getting it working. Is it possible to tell specify source paths it should use for compilation? In cljsbuild:

:source-paths ["src/something" "src/common"]

Azzurite08:10:12

not relevant to the question, but what is the advantage of cli compared to cljsbuild; the reason you want to migrate?

dvcrn08:10:23

just testing waters and learning/understanding the new stuff

👍 1
dvcrn08:10:53

I have a few different build targets, but some packages are shared between all of them and I use source-paths for that

dvcrn09:10:25

hmmm or anyone else an idea how to smartly solve this without source-paths? It's a browser extension. The common page worker is the same in all browsers, the stuff that interacts with the actual page and does it's things But to communicate with the backend of the browser extension it needs to pass messages and call functions that are different per browser. Currently I have a common/ package that has all the shared code in it, then for each browser a myextension.browser package implementation with the specifics for each browser. The common package then uses myextension.browser. During compilation I add the correct myextension.browser package for each builds. Like chrome would be chrome/browser.cljs + common.cljs, firefox would be firefox/browser.cljs + common.cljs and so on The worker can just use browser/do-foo without caring about which browser it's in

zane16:10:14

I'm not sure I understand the question, but it sounds like you might want code splitting? https://clojurescript.org/guides/code-splitting

zane16:10:33

What's the intuition behind why

(cljs.js/eval (cljs.js/empty-state) '+ {:eval cljs.js/js-eval} prn)
returns {:value nil} whereas in Clojure (eval '+) returns #object[clojure.core$_PLUS_ 0x29f0802c "[email protected]"]?

lilactown16:10:46

@zane I think there’s some extra legwork to get cljs.core et. al. when using self-hosted CLJS

zane16:10:26

@lilactown This yields {:value 2}.

(cljs.js/eval (cljs.js/empty-state) '(+ 1 1) {:eval cljs.js/js-eval} prn)

lilactown16:10:41

ah, nvm then

dnolen16:10:31

@zane probably just a bug

zane21:10:30

@U050B88UR I see. So you would have expected the cljs.js/eval snippet I posted to have evaluated to the function +? Should I file an issue? I tried the last several versions of cljs and the they all behaved this way.

zane19:10:43

Interestingly, this works:

cljs.user=> (cljs.js/eval (cljs.js/empty-state) '(identity inc) {:eval cljs.js/js-eval} prn)
{:value #object[cljs$core$inc]}

dnolen19:10:53

yes file an issue, just don't think anybody has cared/noticed that case

1
lilactown16:10:29

here’s a quick demo I set up using the new React Hooks proposal: https://github.com/Lokeh/hooks-demo/blob/master/src/hooks_demo.cljs

williewillus17:10:15

hi, beginner to javascript and cljs how do you specify that you want all your dependencies (cljs itself, closure, ...) compiled together into one big js file? I have a simple namespace that just prints and looking at the emitted js file after lein cljsbuild once. it just reaches into other folders in the target directory to load namespaces

dnolen17:10:42

set :optimizations to :whitespace, :simple, or :advanced

dnolen17:10:44

@williewillus I recommend going through this at least once if you're just starting out https://clojurescript.org/guides/quick-start

williewillus17:10:49

ah, the structure of my :cljsbuild section was wrong (didn't have a nested :compiler submap) thanks!

pcj17:10:53

Is there a simple way to postwalk over a form's collections? Normal clojure.walk/postwalk returns [k v] for map entries and I do not think I can tell with certainty if it's a vector or map entry. Thoughts?

andy.fingerhut19:10:09

There were changes to Clojure/Java in this area in the last year or so. Have you looked at the ClojureScript implementation to see if it tracked those changes? If not, you can of course copy and paste either Clojure/Java's or ClojureScript's postwalk implementation into your own code and tweak it to your wishes.

andy.fingerhut19:10:15

(if indeed it is possible to call a MapEntry constructor in ClojureScript instead of vec on the line I linked to -- not enough ClojureScript-fu in me to tell yet)

pcj19:10:25

Thanks for taking the time to look into it! I'll have to try this weekend and see if I can get it working.

mfikes20:10:36

The change to deal with map entries is still on master

mfikes20:10:09

Oh, wait, perhaps there is another change we need to port... looking for the change...

mfikes20:10:49

The change hasn't yet landed on master: https://dev.clojure.org/jira/browse/CLJS-2909

Matt20:10:17

Hey everyone. I’m new here. I’m trying to figure out what level of support there is for the on going development of some clojurescript libraries. I’m worried that some projects in the community go stale. Specifically, I’m looking into om next, but it looks like it hasn’t been worked on in a little while.

shaun-mahood20:10:56

If you're not already invested in the tooling but like the ideas, Fulcro has a lot of active development and started based on Om Next (http://fulcro.fulcrologic.com/)

2