Fork me on GitHub
#clojurescript
<
2018-11-09
>
jaawerth00:11:32

@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 https://ptpb.pw/o7Dq/cljs

jaawerth00:11:46

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

jaawerth00:11:19

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

jaawerth00:11:57

You might even call that promise function defer instead

jaawerth00:11:28

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

pablore00:11:33

Thanks for the hack!

jaawerth01:11:04

@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): https://ptpb.pw/rfff/cljs

pablore14:11:51

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

๐Ÿ˜„ 4
isaac09:11:24

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

isaac09:11:16

there has anyone can explain to me? very thanks

mkvlr09:11:26

does alter-var-root not exist in clojurescript?

thheller09:11:16

there are no vars at runtime so nothing to alter

mkvlr09:11:42

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

thheller09:11:20

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

thheller09:11:45

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

thheller09:11:37

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

mkvlr10:11:05

understood, thanks!

isaac13:11:28

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

isaac13:11:04

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

isaac13:11:08

it seems the :main has been ignored

carocad13:11:04

@isaac shouldn't main value be a string?

isaac13:11:58

string still not working @carocad

borkdude16:11:08

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

nwjsmith17:11:14

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:

nwjsmith17:11:20

(ns polaris.core
  (:require [React]
            [ReactDOM]))

(defn- app
  [_props]
  (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))

(render)

nwjsmith17:11:47

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

nwjsmith17:11:34

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

martinklepsch17:11:20

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

lilactown17:11:08

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

๐Ÿ™Œ 4
lilactown17:11:30

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

lilactown17:11:56

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

lilactown17:11:46

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

lilactown18:11:34

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

nwjsmith19:11:29

@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
eag19:11:02

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
              :handler
              (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}
        (response
         {:found
          (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)
    ))

Jimmy Miller20:11:24

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

Jimmy Miller20:11:44

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

eag20:11:57

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

eag21:11:24

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.

Jimmy Miller21:11:21

What clojurescript library are you using?

lilactown21:11:20

what are you using to do data fetching @eag?

eag21:11:00

cljs-ajax 0.2.6

eag21:11:52

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

eag21:11:29

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.

lilactown21:11:19

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

lilactown21:11:53

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

lilactown21:11:34

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)

lilactown21:11:28

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

eag21:11:09

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

todo22:11:22

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?