This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-29
Channels
- # arachne (3)
- # bangalore-clj (6)
- # beginners (246)
- # boot (57)
- # business (1)
- # capetown (1)
- # cider (2)
- # clara (1)
- # cljsjs (36)
- # cljsrn (1)
- # clojure (150)
- # clojure-austin (4)
- # clojure-brasil (7)
- # clojure-china (2)
- # clojure-france (3)
- # clojure-greece (3)
- # clojure-japan (3)
- # clojure-russia (38)
- # clojure-spec (25)
- # clojure-uk (25)
- # clojurescript (320)
- # clojurex (1)
- # cursive (38)
- # datascript (48)
- # datomic (23)
- # emacs (29)
- # events (1)
- # funcool (2)
- # hoplon (64)
- # jobs (3)
- # luminus (10)
- # off-topic (26)
- # om (27)
- # om-next (1)
- # onyx (1)
- # parinfer (38)
- # perun (5)
- # planck (19)
- # re-frame (38)
- # reagent (19)
- # remote-jobs (1)
- # rum (2)
- # schema (2)
- # spacemacs (1)
- # specter (8)
- # test-check (10)
- # vim (7)
- # yada (14)
Does anyone have recommendations for datetime library’s for cljs? Ideally something that I can convert to an #inst to send over transit.
actually looks like transit takes a js date object
@kingoftheknoll we use cljs-time with https://github.com/andrewmcveigh/cljs-time/issues/15#issuecomment-173706115
Then you get to use goog.UtcDateTime's which are probably more ideal
Thanks for this!
@bbloom: If I correctly understood your question, I would go with Om Next's tempids, but I'm biased :-)
does om.next keep a permanent mapping of tempids? or are those ids invalidated after a transaction?
They're invalidated after a remote transaction
You should return a mapping from tempid->real id from the txn
And Om Next replaces them for you
yeah, but that means you can’t leak any tempids outside of the transaction context, like if you want to store a pointer in some cache or something
Depends, you can always choose to keep the mappings around
that sorta matches what i did for another project post-react, pre-relay in js, only i made the real id public/explicit
essentially i had every node in the graph labeled with a “lid” (local id) and optionally a “gid” (global id)
then used lids everywhere i could, except when sending messages to the server & translated at the network level
worked out reasonably well, but you had to be aware of the distinction, which was occasionally tricky
Right, but I think we're talking about slightly different things
In Om Next, tempids are supposed to only exist until they're persisted
After which they're automatically replaced by the real ids for the persisted data that the server returns
is it possible to use 2 different versions of the same library in cljs?
reason i’m asking - c3js (the charting library) uses v3
of d3js. but, we are now needing to use v4
of d3js.
(i could also be going around this the completely wrong way)
@biscuitpants if you do it manually yes, but you really don't want to do this to your users. is v3
completely incompatible with v4
?
yep, they made a lot of breaking api changes
its under d3
hahaha
i know already 😕
hmm okay. i will take a look at webpack / rollup
hmm that may actually be a much better idea. but won’t the closure compiler still munge it’s namespaces?
this way lies madness and despair
I guess my plan would be to bundle d3.v3
+ c3js
into one js file that is scoped and only exposes the c3js object
ha, they are indeed. seems like one hell of a lot of work, for a seemingly small advantage.
there is an open PR for d3 v4
on c3js Github, maybe that is in a workable state
Can I somehow permanently redefine/overwrite a function? Like with-redef
but permanent and global. When I’m testing with-redef
works well for sync tests but with asynchronicity it doesn’t apply.
I'm having an issue where we want to request data from a domain other than "localhost" when developing with figwheel. But I can't find anything on adding a CORS header to figwheels responses. Does anyone know how to do this?
@vikeri you may also look at clj-fakes
lib - it provides explicit patch
/`unpatch` functions:
https://metametadata.github.io/clj-fakes/user-guide/#monkey-patching
Here's an example of combining it with async tests:
https://github.com/metametadata/carry/blob/a04058c9ee3fef7e9f7a7971e381408bd22e10f1/examples/friend-list/test/unit/signals.cljs#L52
@metametadata sweet! I'll check it out tomorrow.
I need to pass on-click function through params, via a def that’s declared in a different namespace. Can someone help me with correct quoting syntax? something like
{:options {:on-click (fn [e] (js/console.info “clicked”)}}
so I can attach that to a sablono
element directly: e.g.: (sablono.core/html [:a (:options foo)])
create-ns and alias seem relatively useful for spec, but clojurescript doesn’t really support these - any good alternative other than verbose keywords? (alexmiller sent me here from #clojure-spec)
@bbloom I just create files with only (ns ...)
and :require
them as usual, typically as the specs evolve those files become useful anyways
@thheller that’s what i was doing, but annoyingly, it would now either A) create a cyclic import or B) require i split stuff out in to a namespace just for the shared stuff
i’m probably going to do B, but it would require changing all the namespaces & a bunch of test data files will need to be munged too
@bbloom I’m pretty sure there was discussion about this, it really needs to be handled in Clojure first
sorry probably have no idea what you’re talking about - is :alias
a thing at the ns form level?
in order for alias
to work should probably tweak what @anmonteiro did for require
@alexmiller may be interested in this discussion, with respect to the alias/create-ns patch he had for clj
I have a patch for alias in Clojure that allows it to create the namespace automatically. that’s ready for Rich to look at, but I’m not sure if he will like it or not.
right, but alias is still a dynamic operation & non-bootstrapped cljs needs a static one too
Adding ns support to invoke it is the next step and I’d be in favor of it, but Rich did not seem sold on it the last time we talked about it. Didn’t necessarily seem against it either but was just still thinking about it.
I’m just talking about where we are in Clojure land atm
that will not translate perfectly into ClojureScript but should inform it
thanks. i’m hacking up a temporary solution now - i’ll share it when i’m done, for whatever that’s worth
@bbloom seems less likely which is why we added :refer
support for macros in ClojureScript - not sure if you missed that
oh sorry, no if you want everything to be in one .cljc file you can’t self-reqiure or you’ll stack overflow
@bbloom yes, sorry I was mistaken - you’re doing something for yourself - this doesn’t work that well
the :refer
stuff I was talking about was to make it easier for someone to consume your thing without dealing with cljs/clj differences
i tried to do :use-macros and i got undeclared var warnings suggesting this .clj file was loaded as cljs
(ns my.ns #?(:cljs (:require-macros [my.ns :as m])))
and then use m/my-macro
when inside my.ns
well we’re definitely unlikely to spend anymore time on the macro stuff - however if there’s a better error message to emit - interested in that
what do i need to put in the ns forms of core and util in order to use either mac or func from core
ok i have tried all of these that you’ve suggested and get errors every which way - let me be clear about what i’ve tried & how it failed
(ns ambiparse.util
#?(:cljs (:require-macros [ambiparse.util :refer [reader-alias]])))
Could not parse ns form ambiparse.util Invalid :refer, macro ambiparse.util/reader-alias does not exist
it definitely doesn’t work correctly in planck - but i’ll try it w/ a non-bootstrapped compiler
(ns ambiparse.util
#?(:cljs (:require-macros [ambiparse.util :refer [reader-alias]])))
(defn func [])
#?(:clj
(defmacro reader-alias [& args]
:mac))
(prn (reader-alias :foo))
is there any easy to set up non-bootstrapped repl? or do i need to build it myself from the source?
cljs.user=> (require 'ambiparse.gll) clojure.lang.ExceptionInfo: Could not locate ambiparse/util__init.class or ambiparse/util.clj on classpath. in file ambiparse/util.cljc {:tag :cljs/analysis-error}
yeah, if i remove the require-macros from the util ns it finds it but can’t find the macro itself
the error message seems misleading tho, b/c the classpaths are identical, i’m nto sure what’s different between what i was just doing and that command
(require ‘ambiparse.util) which internally has #?(:cljs (:require-macros [ambiparse.util]))
and via cljs.jar, i have no way to easily access the clj env to forcibly reload the ns on the clj side
~/Projects/ambiparse (cljs!) $ rlwrap java -cp cljs.jar:src clojure.main -m cljs.repl.node ClojureScript Node.js REPL server listening on 50247 To quit, type: :cljs/quit cljs.user=> (require 'http://ambiparse.wtf :reload-all) Error: No protocol method ISwap.-swap! defined for type cljs.core/Atom: [object Object] at Object.cljs$core$missing_protocol [as missing_protocol] (/Users/bbloom/Projects/ambiparse/.cljs_node_repl/cljs/core.js:309:9) at Function.cljs.core.swapBANG_.cljs$core$IFn$invoke$arity$4 (/Users/bbloom/Projects/ambiparse/.cljsnode_repl/cljs/core.js:3054:17) at Function.cljs.core.swap_BANG_.cljs$core$IFn$invoke$arity$4 (/Users/bbloom/Projects/ambiparse/.cljsnode_repl/cljs/core.js:15681:30) at cljs$core$swap_BANG_ (/Users/bbloom/Projects/ambiparse/.cljs_node_repl/cljs/core.js:15642:29) at cljs$spec$def_impl (/Users/bbloom/Projects/ambiparse/.cljs_node_repl/cljs/spec.js:912:22) at Object.<anonymous> (/Users/bbloom/Projects/ambiparse/.cljs_node_repl/cljs/spec.js:4572:20) at Module._compile (module.js:573:32) at Object.Module._extensions..js (module.js:582:10) at Module.load (module.js:490:32) at tryModuleLoad (module.js:449:12)
@bbloom hrm actually you probably found a bug wrt. :reload/:reload-all
in the self require case
yeah I glanced at the :reload/:reload-all
logic and I think I see how this could happen - filed an issue http://dev.clojure.org/jira/browse/CLJS-1863
if in my util ns i do (defmacro mac [] (prn 1))
(note no syntax quote) then from the wtf directory, try to call the macro
but if i comment out the macro, reload, no print (as expected) then uncomment it back in and reload, it prints now
(require '[foo.util :include-macros true] :reload)
might work, I really have no idea though
cljs.user=> (require-macros 'foo.util :reload) clojure.lang.ExceptionInfo: Could not locate foo/util__init.class or foo/util.clj on classpath. at line 1 <cljs repl> {:file "<cljs repl>", :line 1, :column 1, :root-source-info {:source-type :fragment, :source-form (require-macros (quote foo.util) :reload)}, :tag :cljs/analysis-error}
i feel like i’m about to sound like a crazy person, but i’m running in to all sorts of weirdness with debug-prn and some kind of caching or something w/ the reload
i’m finding that ihave to kill repl, do rm -rf .cljs_node_repl, and then restart to get stuff to work
(defmacro reader-alias [alias namespace-sym]
(create-ns namespace-sym)
(clojure.core/alias alias namespace-sym)
(when (find-ns 'cljs.env)
(let [compiler (find-var 'cljs.env/*compiler*)
cljs-ns (find-var 'cljs.analyzer/*cljs-ns*)]
(swap! @compiler assoc-in
[:cljs.analyzer/namespaces @cljs-ns :requires alias]
namespace-sym)))
nil)
adding an :alias form to the ns macro should be very easy - happy to provide a patch if you can talk rich in to it 😛
it sounds like Rich does not necessarily want to add :alias to ns
i tried that, but the analyzer overrides it with that value in that compiler atom path
ok anyway - i’m giving up on this & just making another namespace for specs & other namespaced keywords - and paying the non-trivial vim/grep/sed costs
for the record, i find namespaced keywords to be a lot more trouble than they are worth