This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-09
Channels
- # aleph (3)
- # beginners (327)
- # calva (3)
- # cider (20)
- # cljdoc (59)
- # cljs-dev (40)
- # clojure (104)
- # clojure-dev (30)
- # clojure-italy (8)
- # clojure-nl (36)
- # clojure-russia (3)
- # clojure-spec (3)
- # clojure-uk (79)
- # clojurescript (54)
- # community-development (5)
- # cursive (28)
- # data-science (21)
- # datomic (35)
- # emacs (14)
- # expound (1)
- # figwheel (2)
- # figwheel-main (82)
- # fulcro (18)
- # graphql (13)
- # jobs (12)
- # jobs-discuss (38)
- # kaocha (8)
- # lambdaisland (1)
- # lumo (12)
- # off-topic (20)
- # onyx (4)
- # re-frame (51)
- # reagent (12)
- # reitit (8)
- # ring-swagger (1)
- # shadow-cljs (22)
- # slack-help (2)
- # spacemacs (6)
- # specter (16)
- # testing (3)
@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
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
Just remembered this is Slack, not IRC, so I can use a snippet instead of a paste link ๐
@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
some entry in output-dir/cljsc_opts.edn
not working(eg: :npm-deps, :main
when use clj -A:cljs -d output-dir
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
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
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]
[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)
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
@nwjsmith maybe the links/conversation in this thread are helpful: https://www.reddit.com/r/Clojure/comments/9rmrxf/using_the_proposed_react_hooks_in_clojurescript/
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
(defn- render
[]
(.render ReactDOM (React/createElement app) (.getElementById js/document "app"))
(js/requestAnimationFrame render))
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
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)
))
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)
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?
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