This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-30
Channels
- # announcements (1)
- # beginners (94)
- # calva (12)
- # cider (5)
- # cljdoc (4)
- # cljs-dev (4)
- # clojure (170)
- # clojure-austin (2)
- # clojure-dev (45)
- # clojure-germany (53)
- # clojure-italy (20)
- # clojure-nl (6)
- # clojure-spec (25)
- # clojure-uk (242)
- # clojurescript (161)
- # cursive (16)
- # data-science (3)
- # datomic (20)
- # defnpodcast (6)
- # emacs (40)
- # events (1)
- # fulcro (80)
- # funcool (46)
- # jobs (1)
- # leiningen (23)
- # liberator (2)
- # lumo (43)
- # mount (3)
- # off-topic (21)
- # onyx (1)
- # pedestal (15)
- # re-frame (23)
- # reitit (4)
- # schema (1)
- # sfcljs (1)
- # shadow-cljs (167)
- # spacemacs (1)
- # tools-deps (21)
- # yada (2)
hey, somebody answered this question for somebody else last week and I forgot to save it, because it was interesting to me. I want to create an aliased namespace without making a file. its 2 steps. you do something to create the ns and then (alias ns-sym :as 'alias)
oh! I found it! it was in the clojure channel. https://clojurians.slack.com/archives/C03S1KBA2/p1534946467000100?thread_ts=1534942421.000100&cid=C03S1KBA2
@idiomancy that only works in CLJ though. There is no support for this in CLJS besides creating an actual empty ns.
how can I do a conditional :require
based on whether I’m targetting node or browser?
currently I have:
;; src/foo/core.cljs
(ns foo.core
(:require websocket))
I guess what I want is a custom reader conditional?, e.g. #?(:nodejs ...)
you can create a macro that looks at your compile options and conditionally emits code based on your target
but an important thing to remember is that advanced compilation DCE can eliminate code at compile time so often you don’t have to do this stuff at all
there is also closure-defines, in conjunction with a conditional will almost guarantee dead code elimination
Might be.
Doing some cljs noodling on relaxed vacation at the in-laws. @eggsyntax suggested I join up here.
Shelter Island, NY.
@william Very cool well let me know if I can help. here’s a tutorial https://figwheel.org/tutorial
Good morning! So, what's the cljs answer to intern
? I need to monkey patch a library im using which, in clojure I did by saying
(intern 'external.library.core 'old-function-sym my-function-sym)
@idiomancy well that doesn’t exist
ahh, interesting. Well, I assume it will eventually get used in prod, I'm making a drop in bit of code to apply globally whenever I use garden
I've spoken to noprompt. He has a whole 2.0.0 he wants to roll out that almost has all of the pieces assembled. He hasn't been working on it lately, though - no frontend contracts. So he's unlikely to go for a PR into the version that will become obsolete whenever he decides to keep working on it
I don’t see any reason he shouldn’t accept the PR, but you are probably better off with the forked version than a patch
Yeah, I see what you're saying. what do you think @U06MDAPTP?
Joel, you're the man, we can handle it however you want. You keep doing you and I'll help however I can
thanks, btw @bhauman! sometimes the advice you need is just "yes, you should do it the right way" 😆
On the other hand, by patching the underlying js, you’ll have short-term gratification and long-term job security 😉
@idiomancy i’m fine to patch the current branch. i’ll review your patch as soon as i am able. current status: underwater. 🙂
@idiomancy monkey patching a lib is pretty straightforward though - set!
works for this even under advanced compilation
so on a related note, what's the best way to depend on a github project, like maybe a fork to a popular cljs css repository
@idiomancy With the new tools.deps (deps.edn) you can depend on the commit hash of a project on github directly.
I am making an ajax call and successfully getting {:data "Hello World"}{:data "Hello World"}{:data "Hello World"}{:data "Hello World"}{:data "Hello World"}{:data "Hello World"} back from the database. Problem is I can only see it in my network tab. I can't seem to alert it or write it to a div. Here's my attempt: (defn ajax-input [id] [:input {:id id :on-change #(js/alert (.-value (.send goog.net.XhrIo "/database"))) } ] )
@idiomancy here's an example from https://clojure.org/reference/deps_and_cli
{:deps
{org.clojure/tools.reader {:mvn/version "1.1.1"}
github-sally/awesome {:git/url "", :sha "123abcd549214b5cba04002b6875bdf59f9d88b6"}
;; ... add more here
}}
@its.ramzi ajax is async it doesn’t return the result
Can you help me translate this to clojure: goog.net.XhrIo.send(dataUrl, function(e) { var xhr = e.target; var obj = xhr.getResponseJson(); log('Received Json data object with title property of "' + obj['title'] + '"'); alert(obj['content']); });
@its.ramzi (.send goog.net.XhrIo "/database" (fn [event] ;; get data from event here ))
:on-change #(.log js/console (.send goog.net.XhrIo "/database" (fn [event] (.getReponseJson(.target event)))))
that returns the value of the thing at the property target
, rather than calling a function at that property
Great! Getting closer! json.js:148 Uncaught Error: Invalid JSON string: {:data "Hello World"}{:data "Hello World"}{:data "Hello World"}{:data "Hello World"}{:data "Hello World"}{:data "Hello World"}{:data "Hello World"}{:data "Hello World"}{:data "Hello World"}

So I wrapped my {}s with a []. Now it is coming in as [LazySeq] and still causing the invalid json error
json.js:148 Uncaught Error: Invalid JSON string: [[email protected]]
@its.ramzi don't use .getResponseJson
use .getResponseText
instead
then use (:require [cljs.creader :as reader])
and (reader/read-string the-result)
to convert the text to cljs maps
using .getResponseText gives me: Uncaught TypeError: Cannot read property 'value' of null
I think the "changeme" div isn't loaded yet. (defn change-dom [content] (-> js/document (.getElementById "changeme") (.-innerHTML)(set! (-> js/document (.getElementById n)(.-value)(str content)) )) )
Your code, properly indented, looks more like this:
(defn change-dom [content]
(-> js/document
(.getElementById "changeme")
(.-innerHTML)
(set!
(-> js/document
(.getElementById n)
(.-value)
(str content)))))
I'm not sure what you were trying to accomplish there. But you can probably just replace that last (set! ...
with (set! content)
yeah, I think your above function may have accidentally did that. Try first making a basic function that can add text to a div
Nice! refer to this too when translating from js code: https://kanaka.github.io/clojurescript/web/synonym.html
If one wants to release a ClojureScript lib on NPM and make it maximally usable by the greatest number of JS devs, what are the JS ecosystem things a CLJS dev should take into consideration?
Same thing here - I wish it was a better supported use-case (in my case I may prototype in cljs, but will probably have to rewrite at some point 😑)
that’s just not a very popular thing to do for the reason that nobody will want to use your thing client side unless they’re going to run Google Closure on it
Yeah, I wasn't able to find many libs out there produced with closure. I understand React is ran through it (at FB), but I guess that's just for prod. But if the output is set to :none or :simple, are other minifier/packer tools not able to consume that output?
since what you’d be shipping on npm would have to be code compiled with :none
nobody will be able to handle that
Ah, so datascript is just delivering a minified artifact via npm. And your mori is running lein from the npm build command.
Minified artifacts should be good enough for my target audience, as this is more of a tool, used with code, than a lib.
So, wrt distributing minified CLJS to the JS world, are there any other gotchas or assumptions to be aware of about JS consumers?
if you’re fine with all of these limitations then, sure, datascript & mori are how it’s done
This may be too ambitious, but I'd like to code split my tool into a bunch of different, optional artifacts. If certain modules are pulled, they may pull in other modules (off the CDN). I'm thinking this will all continue to just work, even when being called from the JS side.
I'm targeting browser. I just said npm because that seems like the JS distribution channel most clients will be familiar with.
Could it be possible to make multiple code-splitted-modules available on npm, and once their downloaded and up in a user's assets folder, they'd be in the right place? Similar to how it'd work if they were pulling the root artifact off of a CDN, which also contains the rest of the splits?
I may be getting too esoteric with the use cases. I'm just wondering what I can offer and I'm still learning the JS ecosystem. It seems to change faster than you can learn it though 🙂
I’m getting a WARNING - unreachable code
when trying to compile my project after adding a node module via npm-deps
. Has anyone seen this before?
Hey, does anybody know of anyone know of any good ways to organize components with configurable colors? How do I describe this problem lol.
I'm trying to set up a personal library of components which I can include across projects by putting a bunch of dynamic variables at the top of the namespace. so like
(def ^:dynamic a-color "#ffffff")
(defn a-component [& args]
[:div.box {:style {:background-color a-color}}])
that way I could have those vars dynamically replaced with different configuration sets. right? make sense?
Well here's the thing lol, what do I name the color constants? because like, while I'm programming, I don't want to see, like, *color-001*
as a constant, that's not descriptive at all... but I don't want to say like *green*
if I'm gonna remap it to another color later 😆I feel like I lack the human language to describe color in terms of its function. I've got numbers and colors, and neither one seems appropriate lol
yeah, I guess they should, I guess I should be putting this question to designer friends, because I like, don't know enough conceptual language
when you said "accent" there i was like "oh man thats great!" I'm at kindergarten level for design vocab 😅
ooh, okay, I think I'm getting closer... so, there are a couple ways to choose color schemes apparently. you have have a triadic color scheme or a complementary scheme or a split complementary, etc. Maybe if I make a couple of those pallets, and then maybe have a function that chooses colors depending on what's defined? Man I am over engineering the living hell out of this