Fork me on GitHub

@pablore So, this works - just keep in mind you'll only be able to use this deliver on promises created by the custom promise function. Probably one would want to redo this to use protocols and non-conflicting-with-JS-stuff symbols rather than using aset but it demonstrates the concept at least


though honestly it's a little sketchy - I'm not sure I'd want to do this in production


on the other hand sometimes you have to do this kind of thing even in JS itself - sort of a hacky way to get the old defer API as seen in earlier implementations of JS promises


You might even call that promise function defer instead


Just remembered this is Slack, not IRC, so I can use a snippet instead of a paste link ๐Ÿ˜„


Thanks for the hack!


@pablore couldn't resist making a better version - now you can chain then/catch using ->, and also use them on regular Promises. Also it uses protocols so you'll get cleaner errors if you accidentally try and use deliver/reject on a plain promise (not sure about shadowing catch here but it matches the promise semantics):


You might as well publish your own library ๐Ÿ˜‰

๐Ÿ˜„ 4

some entry in output-dir/cljsc_opts.edn not working(eg: :npm-deps, :main when use clj -A:cljs -d output-dir


there has anyone can explain to me? very thanks


does alter-var-root not exist in clojurescript?


there are no vars at runtime so nothing to alter


but can I call it from clojure on a cljs namespace? Iโ€™m trying to modify a function in a cljs library


there is no safe way to do that no. you can just do (set! js/that.namespace.function replacement) but it must "match" the original


so it'll have problems with variadic functions or multi arity fns


some of the recent issues/patches try to do it reliably for cljs.spec


understood, thanks!


clj -m cljs.main -d node throws Exception in thread "main" java.lang.AssertionError: Assert failed: :nodejs target with :none optimizations requires a :main entry


# node/cljsc_opts.edn
{:verbose  true
 :main     app.core
 :target   :nodejs
 :npm-deps true}


it seems the :main has been ignored


@isaac shouldn't main value be a string?


string still not working @carocad


should the clojurescript dependency have scope provided or test for a .cljc project that can be used only with clojure, or only with clojurescript


Iโ€™d really like to play with React Hooks, but It doesnโ€™t seem to like me calling it from ClojureScript. I get a Invariant Violation: "Hooks can only be called inside the body of a function component." with the following:


(ns polaris.core
  (:require [React]

(defn- app
  (let [[name set-name] (React/useState "Mary")
        handle-name-change (fn [event] (set-name (.-value (.-target event))))]
    (React/createElement "section"
                         #js {}
                         (React/createElement "input" #js {:value name :onChange handle-name-change})
                         (React/createElement "h1" #js {} name))))

(defn- render
  (.render ReactDOM (app) (.getElementById js/document "app"))
  (js/requestAnimationFrame render))



Has anyone had luck getting Hooks to work with CLJS?

Lyn Headley17:11:28

Is it the case that cljs.spec.gen.alpha does not support recursive-gen? I am seeing: ^--- Use of undeclared Var cljs.spec.gen.alpha/recursive-gen


This is definitely the right direction. Will have to do a bit of reverse engineering of reagent, but might be able to figure it out. Thanks @martinklepsch


@nwjsmith you're welcome. Maybe @lilactown is also around some time since he seems to be the original author of that post


@nwjsmith no reverse-engineering of reagent needed. The library used in that post basically does what you're trying to do

๐Ÿ™Œ 4

the only thing I think you need to change is how you call your app component


(defn- render
  (.render ReactDOM (React/createElement app) (.getElementById js/document "app"))
  (js/requestAnimationFrame render))


โ˜๏ธ you need to make sure you create an element out of it


I'm not sure you want to recursively call render tho? I'm on mobile so I can't try it, but I haven't seen that before


@lilactown thanks, that did it! Feel silly for missing that. The recursive call works for tinkering, not intending to get this releasable. Thanks again, you rock

๐Ÿ™Œ 4

I'm new with cljs, I'm doing a simple reagent, ring, compojure project, in order to learn. In my requests I have keywords in my map. When I respond I have keywords in my map. But when it arrives in cljs it does not have keywords any longer. All keys are now strings. Is this how it is supposed to be? I've changed the middleware around, I've put my response in :params. Nothing has worked so far. Maybe this is the expected behavior, I don't actually know.

(GET ""
             {:params (:foo @doc)
              ;; :response-format :json
              ;; :keywords? true
              (fn [res]
                ;; I don't know why the middleware doesn't
                ;; take care of the keys.
                (let [res (keywordize-keys res)]
                  (js/console.log "wat" res)
                  (js/console.log "watzat" )
                  (js/console.log "zat" (res :found))
                  (swap! doc assoc-in
                         [:foo :found]
                         (get res  :found))
                  (js/console.log "doc" doc))
and on the server side I have this Get.
(GET "/s" {s :params}
          (foo? (s :src-str) (s :word))}))
And my handler looks like this.
(def handler
  (as-> app-routes h
    (if (:dev? env) (wrap-reload h) h)
    (wrap-defaults h (assoc-in site-defaults [:security :anti-forgery] false))
    (wrap-webjars h)
    #_(wrap-params h)
    (wrap-keyword-params h)
    (middleware/wrap-json-params h)
    (middleware/wrap-json-response h)


In your first code snippet, you have :keywords? true commented out. If you cahnge that does it fix your problem?


(Not sure what http library you are using for clojurescript)


No. It actually breaks it. And the data are still not keywords.


I dont know what im looking at in the console. It says it's a map, but the keywords are strings. It looks the same with Json and keywords true, but I have been un able to get any values out with those turned on.


What clojurescript library are you using?


what are you using to do data fetching @eag?


cljs-ajax 0.2.6


I started with the simple-web-app lein template and added reagent-forms.


I do have it actually working. It just seems odd that in cljs I always get string keys instead of keywords like I have everywhere else.


well, the kind-of-reasoning behind it is that you're converting JSON to a map, and JSON has strings for keys


your compojure route responds with JSON, so it converts {:foo 1 :bar 2} to {"foo": 1, "bar": 2} before it sends it across the wire


then cljs-ajax marshals the JSON string into EDN, but we need to tell it to also marshall the keys to keywords (if that's what we want)


according to cljs-ajax's docs, :keywords? should tell it to marshall the keys to keywords


:keywords? is only valid with :response-format json. If I turn those on I get nil for a result.


I have a WebGL context (I don't have the canvas). Is there a simple way to check if my WebGL context is webgl1 or webgl2?