This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-11
Channels
- # admin-announcements (10)
- # arachne (2)
- # beginners (74)
- # boot (302)
- # cider (49)
- # cljs-dev (11)
- # cljs-edn (7)
- # cljsjs (13)
- # cljsrn (1)
- # clojure (164)
- # clojure-austin (1)
- # clojure-brasil (3)
- # clojure-finland (2)
- # clojure-greece (4)
- # clojure-russia (48)
- # clojure-uk (11)
- # clojurescript (138)
- # community-development (1)
- # cursive (13)
- # datascript (1)
- # datomic (19)
- # emacs (4)
- # events (1)
- # garden (1)
- # hoplon (123)
- # jobs-discuss (9)
- # keechma (5)
- # lein-figwheel (4)
- # leiningen (2)
- # luminus (15)
- # mount (1)
- # off-topic (8)
- # om (66)
- # on (1)
- # onyx (28)
- # other-languages (2)
- # planck (1)
- # proton (5)
- # re-frame (18)
- # reagent (15)
- # untangled (15)
i would prefer not to roll my own .. it’s been too long since working with all the graphing algos and such to trust my self
Hi everyone! I was trying to use Dexie.js for indexedDB queries the other day, and I couldn’t figure out how to use it from CLJS, because in order to retrieve the database, you have to call a function on an object that changes its internal state, but does not return itself, like so:
// This is no problem:
var db = new Dexie('MyDatabase');
// But now the .version method changes the internal state, but does not return itself – how can I hook into this in CLJS?
db.version(1).stores({friends: 'name, age'});
The example is from http://dexie.org. Thanks for any help! Cheers.can someone explain. I’m still struggling to find right way of using figwheel. So I’ve creater script/figwheel.clj using these instructions: https://github.com/bhauman/lein-figwheel/wiki/SASS-watcher now when I call it from cmd
$ rlwrap lein run -m clojure.main --init script/figwheel.clj -r
it works, but how do I use that script from cider repl? Just evaluating scriptfile’s buffer in repl doesn’t seem to be able to run sass watcherthose instructions are for starting from the command line, but it's clojure so put it on your classpath and call it
yes, watcher doesn’t work if you jack-in. Repl has to be started outside of Emacs and then CIDER needs to be connected to it, otherwise watcher doesn’t work
@jacob: not tested, but something like this should do the trick
(def db (Dexie. "MyDatabase"))
(doto db
(.version 1)
(.stores (clj->js {:friends "name, age"})))
hi guys where can I the Instant write handler of transit in clojurescript ? I couldn't find it in transit-cljs. I would like to write a handler to support Moment object ( to return just date time in javascript then transit date time ).
@nxqd: here’s ours for goog UtcDateTime’s
;;
(def transit-readers
{:handlers
{"m" (transit/read-handler (fn [s] (UtcDateTime.fromTimestamp s)))
"u" uuid}})
(def transit-writers
{:handlers
{UtcDateTime (transit/write-handler
(constantly "m")
(fn [v] (.getTime v))
(fn [v] (str (.getTime v))))}})
@danielcompton: thanks !
Hi, given a Vector of String, what is the easiest way to convert all of those to numbers,
cljs.user=> c
["1" "2”]
@dimiter don't forget the radix parameter or the runtime will "guess" it from the string.
@bostonaholic: Ah, doto
, so it was a case of RTFM. Thank you kindly!
I know TCO was removed temporarily in Babel, but that was primarily due to the need to support it globally I think
@risto: i might be way off here, but I thought loop-recur actually expands to a trampoline?
since it solves recursion in non-TCO hosts...
@bojan.matic I believe you're correct.
How to write this from JS to clojurescript for (var i = 0; i < localStorage.length; i++){ localStorage.key(i) }
(defn local-storage [storage]
(loop [cljs-storage (js->clj storage)
i 0]
(let [length (count cljs-storage)]
(if (seq cljs-storage)
nil
(if (< i length)
(.key (clj->js storage) i)
(recur (rest storage) (inc i)))))))
;;take my untested solution with a grain of salt, I actually never wrote clojurescript before; I'm new to it(for [i (range 0 (count (js->clj storage))] (.key (clj->js storage) i))
would that not work?
@bojan.matic: I thought the trampoline was specific to JVM
i guess @dnolen knows for sure 😄
but I would be surprised if trampolines weren’t implemented for js host as well
@urbanslug: I'm good. you?
@bojan.matic: the for macro seems so much better though.
6ewis: didn’t look too carefully but also def
-> defn
I also don’t know why folks are using clj->js
, I would default to (.-length localStorage)
and (.key localStorage …)
but maybe I’m old school and missing something
this is equivalent to your first js snippet
(doseq [i (range (.-length localStorage))]
(.key localStorage i))
yeah, if it’s mutating localStorage something like jr’s solution makes the most sense to me
we don’t care about the return value here as far as I can tell
doseq is better, since for is lazy
also, we don’t care about the return value, so for
is pointless there too
@bojan.matic: trampoline
exists in ClojureScript
@urbanslug: (dotimes [i (.-length js/localStorage)] (.key js/localStorage i))
that will compile to JS primitive loop, obviously only for side effects and avoids the needless allocations of for
and doseq
etc.
@urbanslug: (local-storage js/localStorage)
oh, my bad, i thought trampolines were made magically by loop/recur…using trampoline
means you have to write functions that return thunks, right?
@bojan.matic: not the case, trampoline
is for writing mutually recursive code w/o blowing the stack as long as you’re ok with the perf tradeoffs
how would loop/recur handle non-primitive recursion then? or is this a non-issue? 😄
I probably should read a JS book and stop guessing at this point but:
(defn get-secret-things
[name]
;; check if logged out if logged-out:
#?(:cljs
(.-log (dotimes [i (.-length js/localStorage)] (.key js/localStorage i)))
(.removeItem (.-localStorage js/window) "secret-things")
(.-log (dotimes [i (.-length js/localStorage)] (.key js/localStorage i)))
)
(fetch-secret-things))
@urbanslug: (dotimes [i (.-length js/localStorage)] (.log js/console (.key js/localStorage i)))
@urbanslug: What's the error message?
@urbanslug: you’re not printing anything in your snippet
@urbanslug: then you need to print
@urbanslug: you probably want (println foo)
@urbanslug (dotimes [i (.-length (.-localStorage js/window)] (.log js/console (.key (.-localStorage js/window) i)))
Well println refused to work because (enable-console-print!) didn’t work in a cljc file even when I used #?(:cljs (enable-console-print!))
Maybe I missed something. Honestly I’m not comfortable with that level of not know what it is that I’m doing.
@urbanslug: try to console print in the repl and see how it goes
What difference is there between the self hosting clojurescript repl and the non-self hosting one? Does the non-selfhosting one work like online ides or something? I wonder why the other needs to make external server requests. “so no external server requests are necessary."
@urbanslug: self-hosted CLJS is exactly what it says, ClojureScript self-hosted in a JavaScript environment. Non-bootstrap needs access to a JVM for compilation
hence the external server requests
@anmonteiro: I think I want the JVM calls one because it mirrors what I’m actually doing, don’t you think?
@urbanslug: I can’t assess what you’re doing without knowing
@anmonteiro: Well compiling clojurescript to js via clojure then to closure
right, yes
then you might want the external requests
Bootstrap CLJS has a few shortcomings, limited macro support being one of those
But I don’t really know every exact detail
@urbanslug: you might find this helpful https://github.com/magomimmo/modern-cljs
Hi all. Im building a React Native app with re-natal. an issue i’ve come across is that for some reason it wants to require the .DS_Store as a javascript module? Any idea how to remove that depenency?
nvm. worked it out. The image scanning code in re-natal just grabs anything in the images directory. might have to open a PR for that.
@urbanslug: self-hosting is really only for people who for some reason can’t leverage the JVM and who can afford to not care about code size
@dnolen: Do you have a good reference for working with different markup engines within om.next like hiccup?
@sbmitchell: no I don’t use hiccup or similar libraries, someone else might know though
@sbmitchell: I would ask in the #C06DT2YSY channel for more opinions
thanks ill check the channel out!
hi guys
how can share state between different clients?
like (reagent/atom {}), how can i make all clients see the changes on it?, maybe i can use this for simple multi player game
or interaction between clients
Anyone worked with Clojurescript and the Google Maps API? I've seen Contour, but I need something a bit more full featured, if it's out there. Just looking to avoid writing stuff in JS if I can help it.
@abdullahibra: last time I tried something like this Firebase worked pretty well for me, I used this wrapper: https://github.com/crisptrutski/matchbox
darwin: can you explain how can i hard-code this, the idea i mean
how can i create on universal atom to be shared between all clients, i can use backend like redis to store the state, or even clojure atom, but when i change reagent/atom to clojure atom i don't get any effect
maybe i can use Ajax to make both interact together
client1 do ajax call to the server, and server update state, and then client2 do the same
i don't know if this are going to be effective and efficient
it synchronizes data across clients, but it is up to you to write the glue code which will publish/merge changes into your ratoms or what have you
firebase is not the only option, there are multiple libraries doing this service of real-time synchronization between multiple js clients, some are fully self-hosted (unlike firebase), but I don’t remember their names from top of my head
maybe http://gun.js.org? (a quick google search for self-hosted firebase alternative)
darwin: thanks man