Fork me on GitHub
#clojurescript
<
2016-10-05
>
Oliver George00:10:00

Question: Is it typical to extend js/Object to implement ILookup to allow destructuring? When working with javascript react components it's typical for callbacks to be passed an object. Js now makes destructuring that convenient. Currently CLJS destructuring doesn't support jsobj.

Oliver George00:10:26

Something like this does the job... I'm wondering if it's a bad idea or common practice.

Oliver George00:10:29

(ns demo-ui.obj-lookup
  "Extends js/Object to implement ILookup so we can destructure."
  (:require [goog.object :as gobject]))

(extend-protocol ILookup
  object
  (-lookup
    ([o k] (gobject/get o k))
    ([o k not-found] (gobject/get o k not-found))))

rnandan27304:10:04

Any ideas on how to dynamically change the meta data in reagent apps for to make it SEO friendly?

Oliver George05:10:38

(set! (. js/document -title) title)

Oliver George05:10:25

@rnandan273 that's how we set things which aren't part of the reagent views. Not sure that would help with SEO though.

rnandan27305:10:59

Thanks @olivergeorge I will deploy the app and check out the results of the Google structured data tool results

thheller08:10:52

@olivergeorge the problem with extending object is that it applies to EVERYTHING since everything is an object in js. not a problem but you may start seeing fuzzy behaviour with :advanced optimizations

thheller08:10:29

react things don't go through it so the ILookup will work

thheller08:10:38

but closure things go through it and might break it

thheller08:10:23

closure doesn't understand ILookup and might even think you are not using the props and eliminate them

thheller08:10:29

long story short: don't 😉

deas09:10:20

What's the idiomatic index-of in ClojureScript?

anmonteiro10:10:31

@deas: (.indexOf [1 2 3] 2) should work with CLJS data structures

anmonteiro10:10:04

(lastIndexOf too)

deas10:10:16

@anmonteiro What does is use for the comparision? ISomthing?

anmonteiro10:10:17

ClojureScript equality

anmonteiro10:10:30

cljs.core/=, which works with IEquiv

deas10:10:50

IEquiv, Thanks @anmonteiro !

dnolen12:10:10

@olivergeorge not typical and as @thheller notes not a good idea

dvorme15:10:23

Just wanted to thank the #hoplon, castra, javelin folks from Adzerk for some amazing tools. I just couldn’t be as productive without them.

lxsameer18:10:44

hey folks, I'm using figwheel with re-frame for a web app, but changing the clojurescript's files do not cause figwheel to restart the server

spieden18:10:47

@lxsameer can you attach your project.clj?

spieden18:10:24

hmm, looks much like mine except that i’ve never used :ring-handler

lxsameer18:10:54

weird, right ?

jrheard18:10:23

any relevant output in figwheel_server.log?

andrewboltachev22:10:10

Hi. Is anyone of you guys interested in converting JS back to ClojureScript (for different purposes)? If yes, please check out the project I've just started, which is intended to do that: https://github.com/andrewboltachev/muchjs

dnolen22:10:38

@andrewboltachev interesting, what use case are you imagining?

andrewboltachev22:10:44

@dnolen like the one presented — say, I want to bring some snippets for some React libs to my CLJS project

dnolen22:10:33

hrm, cool stuff

andrewboltachev22:10:21

Thanks. I'm not sure if I can use any JS React library in CLJS project, however. Many of them are ES6-heavy

andrewboltachev22:10:34

Also IIRC Rich Hickey has once said, that "converting one language to another via Clojure" (or something) is a waste of time. So, may be this is the case. But rough conversion might like this be made possible, I think.

dnolen22:10:36

well generating equivalent code for typical mutable object oriented code isn’t going to be particularly fun - but there’s also the return on investment issue - if you can just consume this stuff anyway by some other means (JS Module processing in Closure) - then maybe the effort isn’t paying it’s own way

andrewboltachev22:10:10

yep I agree, economical side of things is important. And yep, changing all the get/set style to functional one would be challenging, if not impossible (aka NP-complete). I want to see if and where this project would be helpful to me in actual use

jetzajac23:10:20

Hi! did anyone managed to get cljs.spec.test/instrument working? I get an error requiring ns: No such namespace: clojure.test.check

andrewboltachev23:10:55

@jetzajac just trying to guess: may be cljs.test.check?

mattly23:10:40

does cljs.reader on 1.9 not yet support the new namespaced keyword / map key syntax, f.e. #:foo{:bar #:bee{:baz 3}}

jetzajac23:10:37

@andrewboltachev I'm trying to require cljs.spec.test, not clojure.test.check

andrewboltachev23:10:04

ah... well I didn't actually try the Spec yet, so don't know

anmonteiro23:10:47

@jetzajac you need to explicitly require clojure.test.check along with cljs.spec.test in ClojureScript

jrheard23:10:59

that’s odd, that should fix it

jrheard23:10:22

i ran into the same error last week, and requiring [clojure.test.check] fixed it

anmonteiro23:10:30

@jetzajac do you have a dependency on test.check in your project?

jetzajac23:10:26

oh, should I add it separately?

Oliver George23:10:38

@thheller @dnolen Thanks. That makes sense. It would be handy for destructuring to support native jsobj data. Has that been discussed/explored?