This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-11
Channels
- # beginners (2)
- # boot (97)
- # cider (58)
- # cljs-dev (10)
- # cljsrn (7)
- # clojure (79)
- # clojure-austin (4)
- # clojure-brasil (1)
- # clojure-france (1)
- # clojure-russia (42)
- # clojure-spec (12)
- # clojure-uk (22)
- # clojurescript (150)
- # clr (1)
- # conf-proposals (7)
- # core-matrix (2)
- # cursive (4)
- # datomic (9)
- # jobs (2)
- # klipse (28)
- # leiningen (3)
- # lumo (8)
- # nrepl (1)
- # off-topic (28)
- # om (18)
- # om-next (2)
- # perun (17)
- # planck (9)
- # rdf (1)
- # re-frame (18)
- # reagent (7)
- # ring (2)
- # rum (1)
- # specter (11)
- # test-check (3)
- # untangled (1)
- # yada (7)
as a side note, you should consider using https://github.com/binaryage/cljs-devtools
uoww! nice! It's awesome! thanks brother š I'll try it
hey all in a cljc file, if there are not reader conditionals, whatās the default behaviour?
@stbgz Fragments of code not wrapped in reader conditionals is unconditionally compiled for all dialects. There need not be any reader conditionals if the entire file is inherently portable.
I was just wandering, not even searched the internet, if there is a way to clean a project of dead code/function. I especially have some imports Iām not sure whether they are still used after putting some code in multiple files.
How does this
in JS work? This doesnāt:
https://gist.github.com/borkdude/e4eb14ed12bb3d154bda482199b60719
you need to do (.bar o)
same thing
cljs.user=> (def x #js {:bar (fn [] (println "Great success")) :foo (fn [] (this-as this (.bar this)))})
#'cljs.user/x
cljs.user=> (.foo x)
Great success
Works for Me [tm]
@borkdude thanks, I will look into that, I have cursive in intellij, but not really using it atm.
pro tip: try it in lumo, it's easier to experiment that way
Yeah, Iām trying it in http://app.klipse.tech/. It works when I move the this-as
close to the call, like your example. I have no clue how this works (pun intended).
share the failing example?
also
cljs.user=> (def y (reify Object (bar [this] (println "Great success")) (foo [this] (.bar this))))
#'cljs.user/y
cljs.user=> (.foo y)
Great success
Hmm, now this works:
(def o #js
{:foo (fn [] (println "foo"))
:bar (fn [] (this-as this
(println "bar")
((.-foo this))))})
Whatās the difference with before....why do you keep using ((.-foo this))
?
you'll need to use js/bind
in that case (that's just how javascript works)
@pesterhazy Just trying to debug my previous example. @thheller Iām trying to achieve enlightenment š
@pesterhazy I like the reify example anyway, so Iāll be using that from now on
remember, ((.-foo x))
is not equivalent to (.foo x)
@borkdude CLJS tries very hard to never expose you to this
... why are you trying to work around that š
@thheller it's useful to know how things work under the covers
klipse allows you to look at the generated code so that's useful
@pesterhazy things are different in CLJS though, so this
works somewhat different as well
@borkdude vanilla react component as in React.createClass
or via class MyComponent extends React.Component
?
IIRC, if you use this-as, you should immediately bind the value in a let
is that correct @thheller?
I'd be grateful to a pointer to notes on how this-as works in unexected ways
if you have any good code to look at to write some vanilla React, that goes further than only a render method, please share š
@borkdude I'd just use createClass
doing that here: https://github.com/pesterhazy/recalcitrant/blob/master/src/recalcitrant/core.cljs#L103
don't know about "good code" though
@pesterhazy well this-as
exposes you to this
so it inherits all the issues of this
, those should be well documented in the JS world
Thanks @pesterhazy, I think thatāll be useful for me
@borkdude if you are building a JS obj via #js
with functions you intend to call via (.foo obj
) you are basically building a prototype
this looks relevant too http://stackoverflow.com/questions/20597568/clojurescript-this-as-macro-points-to-global-object
one reason I can imagine this-as
may fail is if you're using let bindings, which may be implemented as anon fns
so they'd see a different this
context
(resulting in js/window as this)
@pesterhazy I came across that SO question, but I didnāt understand the answer
right that's the conclusion
what do you mean by"building a prototype", @thheller ?
people use map literals to build Objects in js all the time, no?
without using prototype inheritance explicitly
(let [MyType
(fn []
(this-as this
(set! (.-hello this) "world")))
proto
#js {:foo
(fn []
(this-as this
(js/console.log "this" this (.-hello this))))}]
(js/goog.object.extend (.-prototype MyType) proto)
(-> (MyType.)
(.foo)))
can you use goog.object.extend to make a class that extends React.Component?
that's useful to know
although I'm not sure how es6 classes are any better than React's createClass from the cljs perspective
(defn MyReact [props context updater]
(this-as this
(js/React.Component.call this props context updater)))
(js/goog.object.extend (.-prototype MyReact)
js/React.Component.prototype
#js {:render
(fn []
(this-as this
(js/React.createElement "h1" nil "hello world")))})
(js/ReactDOM.render (js/React.createElement MyReact nil))
let me try that in Klipse
seeing is believing
@pesterhazy how do you add React to Klipse?
give me a second
http://app.klipse.tech/?cljs_in.gist=pesterhazy/39c84224972890665b6bec3addafdf5a&container=1
#error {:message "ERROR", :data {:tag :cljs/analysis-error}, :cause #object[Error Invariant Violation: Minified React error #37; visit for the full message or use the non-minified dev environment for full errors and additional helpful warnings.]}
(js/ReactDOM.render (js/React.createElement MyReact nil) (js/document.getElementById "klipse-container"))
right
minified React errors are not very helpful š
hm it does but the gist doesn't update in Klipse
now it works
http://app.klipse.tech/?cljs_in.gist=pesterhazy/39c84224972890665b6bec3addafdf5a&container=1
nice @thheller !
I think you can just use goog.object/extend
instead of js/goog.object.extend
afaik goog.object is guaranteed to be loaded
as it's used in cljs core
@pesterhazy where can I find that gist feature of Klipse?
IIRC if you want this to work in :advanced
the MyReact
fn needs the @constructor
jsdoc for the closure compiler
the gist needs to be specified in the url
but that doesn't list container=1
which is essential here
I'll ask yehonathan if we can add it there
here's the full manual: https://github.com/viebel/klipse/blob/9edc7e67a31b8a885080f503f1252b230347caef/repl.md
Hey brothers how can I create a action in form to go router ? I'm using secretary, I'm using e.preventDefault but I didn't find how to use to "go url" I puted in my button with type "submit", if I use with :href "/route" it's working ;/
What is the best way to forms ?
i just tried updating clojurescript in one of my re-frame apps, but both 456 & 473 wont work. i think even just the compiling is broken somehow
unit tests via boot-cljs-test just say "Test script not found: cljs_test/generated_test_suite.js"
hey guys, I habe something strange happening in cljs
when setting object; am I doing something wrong ?
(def o (js-obj "first-name" āBaptisteā))
=> #ācljs.user/o
o
=> #js{:first-name āBaptisteā}
(.-first-name o)
=> nil
But if I do this =>
(def o (js-obj "name" "Baptiste"))
=> #'cljs.user/o
o
=> #js{:name "Baptiste"}
(.-name o)
=> "Baptiste"
underscores are more convenient in javascript
ok ok š
as you can use .
syntax rather than ["..."]
for property access
they're possible, but inconvenient
thery are possible !
so remember
it's actually baptiste_from_paris š
right Iāll remember
if i build including that (at least with boot), the js doesn't get written: boot -d adzerk/boot-cljs:1.7.228-2 -d org.clojure/clojurescript:1.9.473 -d io.replikativ/geheimnis:0.1.0 -BP -s foo cljs target
Anybody have any good examples of how to do ajax calls with callbacks via Sente?
I had the impression that Sente was for bi-directional connections. Websockets etc.
Something like cljs-Ajax might be what you are looking for
When I want to use a closure notated javascript library, how would do this?
@olivergeorge yes Sente is amazing at bi-directional work, but there is some initial data that must be loaded with my app, namely: initial posts, user login session variable, user logout session clearing. those three, i've come to conclude, need a simple ajax call to fetch the init data and set the session. then the socket love can happen unhindered
you can also serve the data in the initial html file
[:script#data-transit {:type "text/plain"}
(transit/write data)]
something like that, then just grab that in your cljs code
Yeah, that may actually be the swiftest way... load the necessary noodling with the initial HTML request, I'm trying to balance which will be easier to maintain [long] into the future
Including some data in the html is a good way to avoid an extra round-trip before your single-page webapp can do something useful. I do that for auth and config.
for auth and config? now you're talking my language. how do you do auth?
Oh, to be clear I often do auth using simple HTML endpoints. The auth I was referring to was telling the client what groups/permissions this user has.
That lets me enable/disable features as necessary
e.g. user can add X, user can update Y...
(so my pattern has been: html login page, redirect to the single page app on success)
Not saying that's the best approach but it's convenient.
Yeah that's a good way.
I keep thinking I have to defeat loading times, since there is a couple seconds before the javascript can play, but I should content myself with a working application first, then optimize...
I just don't know how to make a callback do something on the Sente Serverside, but I'm looking x)
is there a support for goog.module? I have a library which provides goog.modules, but don't know how to use them in cljs
@sova: one trick I like is to load the app js on the login screen so it's already cached when the redirect happens
Interesting. Currently I'm actually doing logins from within the javascript app, but I suppose I could just as easily do it outside in a simple form. There is stuff you can do in the app without logging in, so I fink my specific use-case makes it a good design path