Fork me on GitHub
#clojurescript
<
2019-02-14
>
johnj17:02:19

looks like they break backwards compatibility hard https://github.com/google/closure-library/releases

kendall.buchanan17:02:16

I’m finding countless articles online about using Javascript libraries within Clojurescript.

kendall.buchanan17:02:19

How about the other way around?

kendall.buchanan17:02:14

When exporting a cljs project it attaches the library’s api to the global namespace (e.g. window). But, is there a way to export public functions as modules? For example, could I export a CLJS project and host it on NPM?

mhuebert18:02:17

is there a way to check the existence of a key in an object using host interop syntax / in a way that is amenable to Closure compiler renaming? eg. some f for which (f? (.-x #js{:x nil}) would return true

mhuebert18:02:51

(related to exists? but exists? does not do that)

jaide18:02:36

(defn error->stream
  [#js[exit err]]
  (.fromError
   stream
   (.assign js/Object err exit)))
I take it I can’t destructure a js array?

jaide18:02:20

Oh, brilliant! Thanks

mhuebert18:02:23

#js is just for creating arrays / objects

jaide18:02:04

I see, and in the arguments vector you’re not creating an array you’re just listing the symbols to pair with the values

jaide18:02:01

How would you read a dynamic property of a js object?

(def name "msg")
(.-name #js {"msg" "hello"})

borkdude18:02:57

(gobj/get obj "dynamic_property")?

jaide19:02:17

Ohhh, ok thanks. Gotta remember to refer to goog more.

mhuebert19:02:05

I’ve been working on a little library that offers a more clojure-like approach to interop, https://github.com/appliedsciencestudio/js-interop

👌 5
Jacob Haag20:02:59

Would anyone have an idea of merging two anonymous functions into one?

;; Have this function
#(println "foo3")
;; Be merged into this function
#(do (println "foo1")
     (println "foo2"))

dpsutton20:02:23

if your functions are thunks -- ie, arity 0 -- then its not hard

dpsutton20:02:15

(defn keep-callin' [fs] (when-some [f (first fs)] (f) (recur rest fs)))

Jacob Haag20:02:08

Ahh nice, now what if they have a higher arity, let's say 1

john20:02:44

can you comp anonymous fns?

dnolen20:02:37

@mhuebert don't think so, fundamentally anything using the dot operator is subject to Closure renaming unless you hint ^js

dnolen20:02:32

if you look at the analyzer you'll see that externs inference needed to patch resolve-var to kick off externs tracking

dnolen20:02:59

and the dot form needed to change significantly to continue that tracking

john20:02:44

cljs.user=> ((comp #(println "bye") #(println "hi")))
hi
bye
nil

mhuebert21:02:16

@dnolen good info.. I think I meant to ask a slightly different question. Say you have performed (set! (.-x obj) nil). Is there a host-interop way to see that .-x has been set on obj? Thinking along the lines of how clojure lookups distinguish between presence-of-a-key and value-for-key, ie. why (get {:x nil} :x 10) returns nil

dnolen21:02:17

@mhuebert I just don't know what you're asking

dnolen21:02:23

what do you mean "host-interop"?

dnolen21:02:07

also I don't see how .-foo has much to do w/ get/keyword behavior really

dnolen21:02:14

Clojure doesn't mix the two at all

lilactown21:02:28

@mhuebert https://google.github.io/closure-library/api/goog.object.html (goog.object/containsKey obj "x") might be what you're looking for

dnolen21:02:08

that won't work

dnolen21:02:20

because x can be renamed

john21:02:26

I think you can use proxies for that, but that's ECMAScript 2015 I think

john21:02:20

Like, if you want to detect if an object was set or get on

dnolen21:02:36

you might want to look at goog.reflect

dnolen21:02:24

I don't really fully understand what you're trying to achieve, so not sure if I'm sending you in the right direction

dnolen21:02:03

maybe goog.reflect + js-in which is macro for JavaScript in operator

mhuebert21:02:33

By “host interop” I was just looking for closure-rename compatibility. I’ve been working on a js-interop lib that offers the same API as clojure core functions — has stuff like get, get-in, assoc!, assoc-in! and so forth. It mostly compiles down to goog.object calls. After writing the readme and giving a short talk yesterday I started looking deeper into alternatives and was wondering if it is even possible to express clojure’s lookup semantics (specifically this edge case of a key being present but nil) in a host interop / closure-renaming-friendly way. So there is no pressing need, I just didn’t know if I was missing something like (undefined? (.-x obj)). I had it in my head that exists? did this but was mistaken

mhuebert21:02:09

I will have a look at goog.reflect

mhuebert21:02:29

Looks to me like one could do this by using .canAccessProperty and .objectProperty in goog.reflect

mhuebert22:02:16

So then I think I could get a call like (j/get-in o [‘x ‘y] not-found) to compile such that ‘x and ‘y (compile-time constants) are rename-able and the lookup behaviour matches that of regular get-in

mhuebert22:02:50

using quoted symbols vs keywords might be a reasonable way to distinguish between the two behaviours

mhuebert22:02:20

Ie (j/get o :x) vs (j/get o ‘x), static vs renameable

mhuebert22:02:39

But that is beyond the point here.

kwladyka23:02:38

How do you manage resources authorisation in SPA? Like page to log-in only for not logged users, when somebody is logged redirect to right place. When somebody want to open panel and is not logged, redirect to log-in and later back to this URL. Do you use any modules for that?

kwladyka23:02:05

I would like to use something ready, but not sure which library

kwladyka23:02:29

at that moment I use venantius/accountant for navigation and re-frame

kwladyka23:02:02

But I miss pages access and redirections

caleb.macdonaldblack23:02:40

I use a combination of venantius/accountant and clj-commons/secretary

kwladyka23:02:56

How this help you solve the issue?

gklijs06:02:56

I think in general you use some session cookie, and check from the front-end whether you have a valid session, if not set the path to login.

gklijs06:02:02

At least that's how it's working in our Angular/AngularJs hybrids.