This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-27
Channels
- # beginners (54)
- # bitcoin (2)
- # boot (1)
- # calva (10)
- # cider (30)
- # cljs-dev (25)
- # cljsrn (17)
- # clojure (27)
- # clojure-dev (16)
- # clojure-estonia (3)
- # clojure-hk (1)
- # clojure-italy (8)
- # clojure-losangeles (1)
- # clojure-nl (17)
- # clojure-russia (1)
- # clojure-spec (15)
- # clojure-uk (45)
- # clojurebridge (1)
- # clojurescript (95)
- # clojurescript-ios (1)
- # core-async (5)
- # cursive (10)
- # datomic (8)
- # emacs (2)
- # figwheel-main (31)
- # fulcro (99)
- # hyperfiddle (3)
- # immutant (1)
- # jobs (13)
- # jobs-discuss (82)
- # keechma (6)
- # leiningen (3)
- # lumo (1)
- # nrepl (1)
- # off-topic (37)
- # onyx (1)
- # pedestal (6)
- # re-frame (7)
- # reitit (2)
- # remote-jobs (1)
- # ring-swagger (3)
- # rum (6)
- # shadow-cljs (14)
- # specter (4)
- # tools-deps (27)
- # yada (12)
hey cljs, so, tale as old as time, in the next few months I'll be beginning a new project at work but for various reasons clojure/clojurescript is absolutely out of the picture. honestly I'm wincing at the thought of writing JS again, and i've also been out of the JS loop for two years--do any of you have any advice on favorite JS libraries to use for frontend development, or any advice more generally?
I haven’t used it myself, but check this out: http://thi.ng/hdom
Vue promises to get out of the way and minimize fatigue — so it would be “easy” in the Hickey sense. No idea about “simple” though.
Hey! Does anyone know how I can access a Promise (returned by js/fetch)? In JavaScript I just did response.key to get data, but I have no idea how to go about Clojure. All I get right now is #object[Promise (object Promise]]
I actually have identical code all the way till ;; do something
I'm doing all that inside of a (def my-data), and am trying to use that (my-data) like this: (println my-data.key)
which returns "nil"
Also, if you want to check out a more ClojureScript-native way of working with promises, I hear that Promesa is rather good: http://funcool.github.io/promesa/latest/
Hi Henrik!
It uses Bluebird under the hood, because apparently that’s the most performant alternative at the moment.
I'm still very much at the "Hello, World" level. I have more-or-less gotten the hang of DOM manipulation, but working with data (like, getting remote data, turning it into a map or vector, so forth) is still very much new for me.
Are you familiar with Go at all? If you’re OK with working with channels, cljs-http
might offer an easier way of calling a remote resource.
For example,
(ns example.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [cljs-http.client :as http]
[cljs.core.async :refer [<!]]))
(defn my-fetch [url params handler]
(go
(let [result (<! (http/post url {:json-params params}))]
(handler result))))
(my-fetch "" {:foo "bar"} println)
But you don’t have to deal with promises, and it handles the conversion between JSON to EDN for you (both parameters sent, and body returned).
This still only returns a promise
yes it will return the promise. you'll need to handle the response inside the call back
`(def my-data (-> (js/fetch "https://...") (.then #(.json %)) (.then js->clj) (.then (fn [response] ;; do something )) (.catch #(js/console.error %)))) (println my-data)
Yea, I have no idea how to extract data from it. Everything I've found on Google just leads to another promise
but your example doesn't work in js either. If you assign what comes out of fetch, it'll always be a promise.
Yes but there I can do return response.json()
and then in another .then block use the data
however, I'm happy to say I got data working!
Alright so I got it working. I'm using the cljs-http.client and async macros and the returning JSON is accessible as Clojure vector, or so it seems. Thank you for your help guys! 🙂
I'm actually very excited about this 😄
It's a bit odd for me that accessing nested data goes like (:data (:that (:goes (:deep data))))
, but I suppose I can get use to that
Oh that's cool!
It takes data and calls functions on it in order, so it’s not limited to keys.
(-> 1 inc str vector)
;; => ["2"]
Be aware of ->>
as well. The difference is what parameter the argument is mapped to for the subsequent functions.
https://clojuredocs.org/clojure.core/-%3E%3E
also can use (get-in data [:deep :goes :that :data])
with option to provide default value as well (get-in data [:deep :goes :that :data] default-value)
So say that I set global state (set! js/app-name "Loading ...")
and then get the actual name with a async call to an API. How do I overwrite js/app-name
so it changes throughout the application?
As much as I've read, everything is immutable (constant), which means I can't, right?
If you’re building a webpage, have a look at Reagent for a straightforward way to handle components (functions, really), and state: http://reagent-project.github.io/
Basically, it functions on the notion of a reactive atom. So instead of set!
you would swap!
some value in the atom, and all bits of the page that relies on it will be re-rendered automatically.
Specifically, check out this example for how state is handled:
(ns example
(:require [reagent.core :as r]))
(def click-count (r/atom 0))
(defn counting-component []
[:div
"The atom " [:code "click-count"] " has value: "
@click-count ". "
[:input {:type "button" :value "Click me!"
:on-click #(swap! click-count inc)}]])
(it’s taken straight from the example in the URL above)I've noticed clojurescript method names sometimes have dash (`-`) prefixes, like these https://github.com/omcljs/om/blob/master/src/main/om/core.cljs#L64
what's the meaning of that convention?
is there a way to customize the compiler output when compiling clojurescript through lein cljsbuild?
to be able to develop clojurescript nodejs apps with figwheel, having a repl and testing locally apis through AWS sam
@myguidingstar To avoid collisions with other names, it became idiomatic in ClojureScript to name protocol functions with hyphens. It doesn't semantically convey anything; it is just a convention. (Source: Stuart Halloway in Clojure Inside Out.)
@mfikes thanks for the info, though it's still unclear to me whether that convention is useful or not 😞
tbh I find the hyphen prefixes ugly 🙂
Oh, it is very helpful. For example, when implementing name
, which works on keywords and symbols, there is an INamed
protocol that defines -name
. This allows Keyword
and Symbol
to define -name
without colliding with name
. It also allows name
to be used in contexts where you don't want it to be a protocol function: name
works on strings without having to extend INamed
to them.
(So one pattern is to not call protocol functions directly in your code, but indirect through un-prefixed regular functions: In that case, the regular function can often be the place where you can implement cross-cutting functionality, like validation, etc.)
Here is a concrete example of common stuff being done in a regular function foo
:
(defn- service-provider [opts]
(or (::service-provider opts) (default-service-provider opts)))
(defn foo [representation signature opts]
(-> (-foo (service-provider opts) representation signature)
(assoc :type ::foo)))
In this particular example, even the object being operated upon has been essentially pulled out and moved over into opts
.
hmm, this convention seems to be used in cljs only, or am I wrong?
So, if you see -foo
, it in fact may be the result of it either being in ClojureScript, or code heavily influenced by ClojureScript's implementation.
It is an interesting question as to whether this is common outside of that subset.
I think -foo
makes sense if it’s like ClojureScript, implementation thing and it will be wrapped by foo
To be honest, that’s what -foo
has started to meant to me when I see it (internal implementation, most likely protocol)
What do people recommend here for routing? (I'm looking for simplicity over anything)
Thus far anything I've looked at seems unnecessarily complicated. Like, is it possible to do (route "/article/:id" "function-to-call")
or something?
And then simply (defn function-to-call (str "Hola!"))
compojure does that https://github.com/weavejester/compojure
Ah that looks exactly what I need. Is it compatible with CLJS?
I've never found a router for single-page apps that didn't feel complex. but also routing is kind of a tricky business, and it feels straightforward until it isn't anymore.
(but I'll have need of one soon too, so let me know what you find!)
I’ve been using secretary + accountant, and while I won’t say they are simple or elegant, they do work.
if I were going to start again afresh I’d probably use reitit just because metosin seems to produce very well thought through libraries
i do reverse routing. instead of keeping a central routing table to know on which page what I want to show, for each higher order visual component for which this is an issue, I keep a list of urls where to show it.
It uses cljs-ajax
and there's no mention of node on the README https://github.com/JulianBirch/cljs-ajax
@justinlee just watched a metosin talk today. Good stuff
Seem to 'get' what clojure is all about