Fork me on GitHub
#clojurescript
<
2021-03-18
>
frerom12:03:54

I'm looking into licenses and ClojureScript is under EPL along with a lot of ClojureScript libraries. Since JavaScript in a browser is technically a distribution (from what I understand) then anyone developing a website with ClojureScript would have to disclose the source code and also include the EPL license. Is my understanding of this correct?

phoenixjj12:03:07

"Linking to code (for example to a library) licensed under EPL automatically does not mean that your program is a derivative work."

phoenixjj12:03:39

As long as you are not modifying clojurescript or lib source code you are fine.

phoenixjj12:03:54

this is what I understand.

frerom12:03:45

Thanks @phoenixai2082, that would make sense. If anyone else has a different view, please share!

fsd15:03:15

Hi There, I am working on a react-app, I have this function for for map icons, I am having an issue when I click on Icons in  `yarn start`  it works (it gets the id), but when I use the `yarn build`  build file and click on Icon, it gets id as nil. I am not sure whats causing this to behave this way. Uncaught (in promise) Error: Vector's key for assoc must be a number.

(defn on-click-map-icons [event props page]
     (def feature (first event.features))
        (println feature.properties.itemid)
    (when (= page "results")
    (if   (= feature.source "selected-item") (router/redirect! props :router {:page "item" :item (:id {:id itemid })}) ))
    (when (= page "item")
        (if (= feature.source "subitem")
          (router/redirect! props :router {:page "item" :item (:id {:id itemid } ) :subitem (:sub-id {:sub-id subitemid})  }))))

p-himik15:03:57

Don't use . that way. Stuff like event.features should be (.-features ^js event). The ^js part can be there only once where you first define the name - in this case, right in the signature, like [^js event props page].

fsd15:03:21

Thanks @U2FRKM4TW for pointing that out, I’ve tried using

(defn on-click-map-icons [event props page]
     (def feature (first (.-features ^js event)))
    (when (= page "results")
    (if   (= feature.source "selected-item") (router/redirect! props :router {:page "item" :item (:id {:id feature.properties.itemid })}) ))
    (when (= page "item")
        (if (= feature.source "subitem")
          (router/redirect! props :router {:page "item" :item (:id {:id itemid } ) :subitem (:sub-id {:sub-id feature.properties.subitemid})  }))))
Still got Error: Vector's key for assoc must be a number.

p-himik15:03:09

I didn't mean just that interop with event - I meant all interop field access in your code.

p-himik15:03:04

Also, you probably want to use let instead of def.

fsd15:03:08

Ah I see

fsd16:03:55

@U2FRKM4TW I am able to get to properties like

(.-properties ^js feature) 
#js {:title sample_note,  :noteid 3}
how do I go inside the object and get title? For example feature.properties.title

p-himik16:03:24

Choose any one or a combination or them:

(.. feature -properties -title)
(.-title (.-properties feature))
(-> feature .-properties .-title)
(. (. feature -properties) -title)

p-himik16:03:16

CLJS/JS interop and CLJ/Java interop are almost identical. Completely identical if you don't go outside of the . and -.

fsd16:03:41

Thank You

leif17:03:24

When using webpack in javascript, I can do something like:

function dynamic-load() {
  require("path/to/module");
}
Is there any way to do this sort of thing in clojurescript (when using the :bundle target)?

p-himik19:03:27

No, all requires have to be a part of an ns form. I'm not familiar with dynamic load in webpack. Is it loading the module during the run time, when e.g. some relevant component is requested? If so, then CLJS have module splitting for that.

martinklepsch19:03:26

I’m using ^:export to export a sort-of feature flag to be changed from the console but it looks like the boolean value is inlined wherever it is being used, meaning setting it does not actually propagate to the various sites where it’s used. Is there a way to avoid this type of inlining for specific vars? (In the meantime I fixed this by using an atom.)

dnolen20:03:07

@martinklepsch I don't think you can export value? I recall running into this - only functions

👍 3
lilactown23:03:32

writing a CLJC lib that returns either Clojure promise or a JS Promise and really missing async/`await` 😞

lilactown23:03:03

gotta split my test suite between CLJ and CLJS, even though the semantics are basically the same

lilactown23:03:49

the dream would be I could do:

#?(:clj @(f/send n msg)
   :cljs (await (f/send n msg)))
Alas,

didibus08:03:50

You can't use <p! ?

nilern09:03:22

The test framework has no more special support for core.async than for Promises and I suspect <p! is cljs-only as well

didibus15:03:41

Well I was thinking cause he wants to block on the promise return is my guess. So if he makes the cljs code in a go block with <p! he'd get the blocking behavior. But I guess not really since the go block itself will be async now. The same way you said await would just move the problem up as well.

didibus15:03:44

I think I'd just make the clj code async as well. Maybe use CompletableFuture instead of a Clj promise, since those have a much similar interface to JS promises

didibus16:03:16

Using Promesa maybe could also help. It is already Clj and Cljs compatible.

lilactown17:03:00

I did end up using core.async and <p!

lilactown17:03:32

it still required me to split my tests between CLJ and CLJS as I needed to wrap things in async and go

lilactown17:03:52

In general I'm trying not to pull in too many external libs

didibus18:03:46

Fair enough. I think nilern is right though, I'm not sure await would have helped, because you can only use await inside of async, similar to how you can only use <p! inside go. So you might have had to shenanigan things either way. It's the whole colored function problem.

lilactown18:03:14

yeah like I said, I'm stating my dream; not a call to action 😛

didibus19:03:01

Haha ya. Its going to get a bit weirder too, because Java will get green threads, and CLJ will probably use that for async. But CLJS will need to stick to async/await or go/<p!

lilactown19:03:51

as penance for my griping, I'll post the solution I came up with this morning to merge my (potentially async) tests back into one CLJC file:

(ns flex.test-macros
  (:require
   [clojure.core.async :as a :include-macros true]
   #?(:cljs [cljs.core.async.interop :as ai])
   [clojure.test :as t :include-macros true])
  #?(:cljs (:require-macros [flex.test-macros])))

(defmacro async-test
  [& body]
  (if (some? (:ns &env))
    `(cljs.test/async done# (cljs.core.async/go ~@body (done#))) ;; CLJS
    `(do ~@body)))


(defmacro <<
  [p]
  (if (some? (:ns &env))
    `(cljs.core.async.interop/<p! ~p)
    `(deref ~p)))
and an example usage:
(t/deftest input
  (async-test
   (let [n (f/input 0)]
     (t/is (= 0 @n))
     (<< (f/send n inc))
     (t/is (= 1 @n))))
thanks @nilern for the push in the right direction

🙇 3
didibus20:03:13

Oh, nice solution you found in the end!

lilactown19:03:51

as penance for my griping, I'll post the solution I came up with this morning to merge my (potentially async) tests back into one CLJC file:

(ns flex.test-macros
  (:require
   [clojure.core.async :as a :include-macros true]
   #?(:cljs [cljs.core.async.interop :as ai])
   [clojure.test :as t :include-macros true])
  #?(:cljs (:require-macros [flex.test-macros])))

(defmacro async-test
  [& body]
  (if (some? (:ns &env))
    `(cljs.test/async done# (cljs.core.async/go ~@body (done#))) ;; CLJS
    `(do ~@body)))


(defmacro <<
  [p]
  (if (some? (:ns &env))
    `(cljs.core.async.interop/<p! ~p)
    `(deref ~p)))
and an example usage:
(t/deftest input
  (async-test
   (let [n (f/input 0)]
     (t/is (= 0 @n))
     (<< (f/send n inc))
     (t/is (= 1 @n))))
thanks @nilern for the push in the right direction

🙇 3