Fork me on GitHub
#clojurescript
<
2016-05-09
>
sbmitchell00:05:04

@abdullahibra: "links and images have the same id" -> Elements should never share IDs. The way you have phrased your question its hard to help you. Could explain what you are trying to accomplish a little clearer? Perhaps even showing the code you have as an embedded "snippet" instead so we can read it better.

xcthulhu05:05:49

Hey, so I'm implementing an ECDSA signature system in clojurescript, and I want to use the window.crypto object

xcthulhu05:05:02

Unfortunately, PhantomJS doesn't implement this

xcthulhu05:05:41

And I would really like to use PhantonJS for testing

xcthulhu05:05:43

Any ideas on how I can go about doing this? I can just use Math.random() but it's really insecure.

xcthulhu05:05:44

n/m looks like I just have an old PhantomJS

genRaiy06:05:20

Thanks @ivanreese that's great feedback

sandbags10:05:19

note to self: if you start getting baffling errors about str.call is not a function, check you didn’t stupidly (let [str …]) above

sandbags10:05:41

that’s 20 minutes of my life i am never getting back

schmir10:05:29

at least you learned something

sandbags10:05:11

i might hope so @schmir but i’m not counting on it simple_smile

abdullahibra11:05:47

i'm trying to make an event for when clicking link i got src of img inside the link, my code http://www.refheap.com/118860

abdullahibra11:05:56

can anybody help please in this?

alun12:05:31

@abdullahibra: I guess the problem is in (js/$ this) try (-> event .-currentTarget js/$) instead, even better find a way of doing this with google closure library instead of jQuery

abdullahibra12:05:57

alun: it's working now but i still only get working for the first link image, and i get no effect for the other link images, the current code is: http://refheap.com/118865

risto13:05:41

@dnolen: What's the status of core.typed for clojurescript? Are/will there be any efforts to get it working again?

dnolen13:05:58

@risto: I don’t work on core.typed

dnolen13:05:22

but far as I know, ClojureScript support has stalled mostly for lack of time

risto13:05:50

Yeah I figured. It would be a nice to have since I'm kind of stuck with Node on the backend

risto13:05:24

I tried the Clojure compiler type checking on the wiki (Compile-Time-Type-Checking) also, but it's giving really noisy errors from the closure compiler and clojurescript libs that I want to ignore.

lewix13:05:08

anyone coming from react/redux?

dnolen13:05:36

@risto yes that stuff is not fully baked - still needs a lot of work - and ultimately it can only do limited kinds of checking

lewix13:05:39

oop wrong channel

urbanslug13:05:28

Can I do something like ???

:on-click (fn [e] 
                  (go (let [[x] (<! (chan-returning function))]
                          (println x))

fasiha14:05:08

@urbanslug: yes I believe so. Or, since go blocks have some (small) cost, you could consider core.async's take!: (fn [e] (take! (chan-returning function) println))

ag16:05:36

can anyone tell me how can I add npm dependencies in clj.boot project. for lein there’s lein-npm plugin, I’m thinking about switching to boot.

spiralganglion17:05:41

@ag that might be a good question for #C053K90BR

cky17:05:01

Is there a more idiomatic way to express something like:

(cond
  (number? x) …
  (string? x) …
  (sequential? x) …
  (associative? x) …
  :else …)
It doesn’t seem like something I can extract into multimethods, but if there is a way, I’d love to learn it. 😄

cky17:05:01

(I asked here instead of #C03S1KBA2 because I’m not sure if the way for doing this differs between Clojure and ClojureScript, and I’m coding with the latter.)

borkdude17:05:48

@cky: maybe protocols?

cky17:05:17

@borkdude: I’ve been thinking of that too, I’m just a little lost on the details of how to achieve it.

borkdude17:05:43

@cky: multimethods seem more natural to me if you have only one function for each type

cky17:05:38

Right, I’d like to be able to use either multimethods or protocols. I guess the question is how to make it so that all sequential? types get dispatched one way, all associative? types another, etc.

ddellacosta17:05:49

@cky: if each of your cond predicates can be reduced to a type-check, then extending a protocol seems like a natural fit

ddellacosta17:05:28

I’m not convinced that the cond is so bad in and of itself, depending on the context

cky17:05:14

@ddellacosta: Right, I was wondering how you might write the extend so that it matches all sequential? types or all associative? types, etc. I guess you’re right in the latter statement that cond might be the way to go.

lewix17:05:40

cky:

(extend-protocol Help
  java.lang.String
  (try-me
    ([] "string implementation")
    ([x y] (str "Hello" x "and" y)))

  java.lang.Object
 (try-me
   ([] "Object implementation")
   ([x y] (str "Hello" x "and" y))))

lewix17:05:45

something like that?

ddellacosta17:05:31

6ewis cky yeah but that’s not going to work for sequential? and associative? which are themselves checking whether the type itself satisfies a given protocol. For example: https://github.com/clojure/clojurescript/blob/dd589037f242b4eaace113ffa28ab7b3791caf47/src/main/cljs/cljs/core.cljs#L1978-L1980

cky17:05:56

Right, what @ddellacosta said.

ddellacosta17:05:24

I’m honestly not sure how you’d do this meaningfully with a multimethod either…

ddellacosta17:05:53

again, there is some missing context here that makes it hard to suggest an alternative to the cond

ddellacosta17:05:09

the predicates are testing something that seems like it could be any of a number of types

lewix17:05:32

(defmulti example class) 

(defmethod example java.lang.String [input] 
  (str "String -" input))

(defmethod example java.lang.Long [input] 
  (str "Number - " input))

cky17:05:50

The context here is I'm trying to reimplement cljsjs/classnames in native CLJS so that 0 is treated as truthy.

cky18:05:22

I also like being able to use native Clojure data structures, too. 😊

ddellacosta18:05:25

6ewis: again, how do you test the values which are being checked for satisfying a protocol with the multi-method? class doesn’t suffice here

cky18:05:39

whereas cljsjs/classnames only works with JS arrays and objects.

lewix18:05:43

@ddellacosta: can't we do something along those lines:

(defmulti example input )

(defmethod example  (fn [arg] (associative? arg)) [input] 
  (str "associative -" input))

lewix18:05:55

grr don't mind me

ddellacosta18:05:26

I see the path you’re going down, but even if it were possible, the question you then have to ask yourself is: why bother using a multi-method?

ddellacosta18:05:49

at a certain point it’s far more obvious what is going on with the cond

lewix18:05:01

ddellacosta: I see. aren't protocol optimized for type dispatch?

lewix18:05:32

I should probably head back to my work. I'm not being helpful , just adding more fuel to the fire 😉

ddellacosta18:05:34

@lewix: I don’t know much about the performance characteristics of protocols, but the conventional knowledge is that multi-methods are slower for doing something like type dispatch

ddellacosta18:05:45

when the two are compared in that sense

ddellacosta18:05:10

@lewix heh…it’s fun to try to figure this stuff out though, I get it 😄

lewix18:05:53

@ddellacosta: thanks for your input

ddellacosta18:05:25

@lewix: np. FWIW, here’s a great piece by @alexmiller, exactly on point: http://insideclojure.org/2015/04/27/poly-perf/

ddellacosta18:05:53

also @cky take a look ^

ddellacosta18:05:26

although, I suppose that’s Clojure vs. CLJS so maybe the performance measurements will not be relevant, but the rule of thumb guidelines in the beginning are useful

ddellacosta18:05:40

per your question above 6ewis, he says > Protocols maximally leverage the type-based dispatch built into the JVM.

ddellacosta18:05:52

so, there’s that

Nicolas Boskovic18:05:22

I'm having an issue with reagent where after I refresh a div full of components, after performing a search, the first result of the list is rendered as the first result of the first search performed, always

Nicolas Boskovic18:05:46

It's not a data issue as I've checked that, so I suppose somewhere there's an issue in the DOM but I can't quite pinpoint it

madvas19:05:58

Is in clojurescript core something like lodash’s _.toPlainObject? https://lodash.com/docs#toPlainObject

cky19:05:38

@ddellacosta: Thanks for the link! I'll check it out when I get home, and true, I think there're cases where cond is indeed the best choice. I was trying to get a feel for whether this is one of those situations, or whether I was missing an obvious technique. Thanks for your input!

ddellacosta19:05:05

@cky you’re welcome, and thanks for asking—I learned something too investigating the question!

cky19:05:03

I got feedback from 2 others in my local dev group who also feel that cond is the best approach in this instance. Yay for data points. ☺️

ddellacosta19:05:31

there ya go 😉

borkdude20:05:42

@madvas: do you mean clj->js ?

sandbags21:05:08

Is anyone aware of a Selmer style template library for ClojureScript? I don’t need the full complexity of Selmer (template files and so on) but I have string creation needs that make str a little cumbersome.

sandbags21:05:52

(I’m not trying to create markup)

dimiter21:05:42

Anyone got tips on alternative for slideToggle in CLJS

sandbags22:05:18

Hrmm… the cuerdas library gets me most of the way there

vinnyataide23:05:56

Hello, I'm fairly new to clojure learning by the book Clojure for the Brave and True. But I'm seeing some barrier between that content and the sheer ammount of react's facade out there for clojure. I'm a former React/Redux programmer. Any way to get started in how to plan a react with optional server rendering and god help me something besides rest, like graphql?

vinnyataide23:05:10

Thanks for the awesome job guys

misha23:05:48

@vinnyataide: rum supports server-side rendering. https://github.com/tonsky/rum

vinnyataide23:05:23

what is datascript and how it relates to transit?

misha23:05:54

don't know about "plan" part, but usually you'll have some pocket with app state (atom, datascript db, etc.), and your components will: 1. react to its changes. 2. update it. how exactly will you init/keep that state in sync with back-end - is up to you. could be REST, could be single "smart" endpoint

misha23:05:05

datascript is a front-end (and now a back-end too) "clone" of Datomic data base. with datalog as query language and cool "pull" feature.

misha23:05:38

Transit is a format and set of libraries for conveying values between applications written in different programming languages. read "json on steroids"

misha23:05:11

basically data serialization format w/o type-information loss*. (* terms and conditions may apply)

vinnyataide23:05:25

gonna search about this cool pull feature

misha23:05:44

the keyword is pull api

vinnyataide23:05:21

I'm seeing the datomic architecture

vinnyataide23:05:29

seems hard to believe it works

vinnyataide23:05:34

every app as a brain

risto23:05:25

@vinnyataide: Yeah it's definitely an interesting idea. I think it uses caching heavily. I haven't explored it very much yet, but I'm wondering if it's using websockets to inform clients of db updates