This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-14
Channels
- # announcements (1)
- # beginners (206)
- # calva (2)
- # cider (64)
- # cljs-dev (12)
- # clojars (2)
- # clojure (177)
- # clojure-europe (2)
- # clojure-finland (1)
- # clojure-italy (2)
- # clojure-losangeles (5)
- # clojure-nl (7)
- # clojure-russia (69)
- # clojure-spec (41)
- # clojure-uk (92)
- # clojurescript (60)
- # core-async (16)
- # cursive (48)
- # data-science (6)
- # datomic (73)
- # duct (5)
- # events (2)
- # figwheel-main (5)
- # fulcro (29)
- # hoplon (1)
- # off-topic (52)
- # pathom (11)
- # reagent (4)
- # reitit (5)
- # remote-jobs (1)
- # rum (7)
- # shadow-cljs (58)
- # slack-help (10)
- # spacemacs (3)
- # testing (3)
- # tools-deps (5)
looks like they break backwards compatibility hard https://github.com/google/closure-library/releases
I’m finding countless articles online about using Javascript libraries within Clojurescript.
How about the other way around?
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?
@kendall.buchanan it is possible if you really want to, see for example https://github.com/tonsky/datascript#using-from-vanilla-js
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
@isak Thank you!
(defn error->stream
[#js[exit err]]
(.fromError
stream
(.assign js/Object err exit)))
I take it I can’t destructure a js array?@jayzawrotny you can, but without that #js
. https://www.maria.cloud/gist/8ad61d0ce1d93a7d64551e57abf89b64?eval=true
I see, and in the arguments vector you’re not creating an array you’re just listing the symbols to pair with the values
How would you read a dynamic property of a js object?
(def name "msg")
(.-name #js {"msg" "hello"})
yep, https://github.com/google/closure-library/blob/master/closure/goog/object/object.js#L426
I’ve been working on a little library that offers a more clojure-like approach to interop, https://github.com/appliedsciencestudio/js-interop
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"))
Ahh nice, now what if they have a higher arity, let's say 1
@mhuebert don't think so, fundamentally anything using the dot operator is subject to Closure renaming unless you hint ^js
if you look at the analyzer you'll see that externs inference needed to patch resolve-var
to kick off externs tracking
@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
@mhuebert https://google.github.io/closure-library/api/goog.object.html
(goog.object/containsKey obj "x")
might be what you're looking for
I don't really fully understand what you're trying to achieve, so not sure if I'm sending you in the right direction
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
Looks to me like one could do this by using .canAccessProperty and .objectProperty in goog.reflect
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
using quoted symbols vs keywords might be a reasonable way to distinguish between the two behaviours
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?
I use a combination of venantius/accountant
and clj-commons/secretary