This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-23
Channels
- # beginners (63)
- # cljs-dev (1)
- # cljsjs (1)
- # cljsrn (11)
- # clojure (208)
- # clojure-berlin (2)
- # clojure-dusseldorf (5)
- # clojure-italy (5)
- # clojure-norway (56)
- # clojure-russia (7)
- # clojure-spec (85)
- # clojure-uk (27)
- # clojurescript (191)
- # core-async (73)
- # cursive (4)
- # datomic (62)
- # defnpodcast (1)
- # hoplon (2)
- # jobs-rus (1)
- # juxt (14)
- # keechma (1)
- # leiningen (1)
- # lumo (126)
- # off-topic (2)
- # om (11)
- # onyx (27)
- # pedestal (52)
- # planck (21)
- # powderkeg (1)
- # re-frame (32)
- # reagent (14)
- # ring-swagger (1)
- # rum (3)
- # slack-help (19)
- # specter (23)
- # untangled (32)
- # vim (7)
- # yada (43)
Suppose I have a javascript function as a string in cljs. Such as: (def s (str inc)) (= s "function cljs$core$inc(x){\nreturn (x + (1));\n}") how could I then call s, as in: (s 1) => 2
@john (js* "alert('my special JS code')")
from: http://www.spacjer.com/blog/2014/09/12/clojurescript-javascript-interop/
Hi everybody. I’ve been using Clojure on the backend for some time now, and I would like to start with cljs, too. I have a toy web project in mind (Scrum Poker Web App), where users can simultainously pick cards, and the selection is pushed to other webclients immediately. Right now I need to pick frameworks, and found this page: https://github.com/hantuzun/awesome-clojurescript#web-framework—template. What would be a popular, but already well established choice for a front- and backend combination? My frontend experience is mainly restricted to Angular JS and the bloaty Java server side frameworks (I am not a fan of server side html generation…).
(I don’t have any experience with reactive programming, but also would like to have a shot at it)
@javahippie you could go with something like chord: https://github.com/jarohen/chord
But if all you are doing is mostly broadcasting state changes between clients, you don't need too much on the backend
@javahippie on the frontend there's been a lot of interest in re-frame and Reagent
Does anyone know if it is possible to get the source of a function using cljs.repl/source programmatically, while not at the repl?
chord looks great, and I will check re-frame and reagent. Thank you very much, I appreciate your recommendations!
I'm guessing after advanced compilation, cljs.repl/source will no longer have access to the original symbols?
@javahippie absolutely!
hi guys, I would like to use this package https://github.com/algolia/instantsearch.js/tree/v2/packages/react-instantsearch in my application. What is the easiest way to do it ? Thanks
@john why do you need the source of a function? that will only lead to very questionable results at best
it's moreso of an experiment. I'd like to make a defworker which does a defn (with-meta name {:source (actual source)}).
then you can pass that function to a worker like you would to an agent. And the worker then updates its state, like a worker.
Any defworkers you evaluate on an agent could potentially remember the function definitions on the worker side, allowing you to feed in a series of definitions to initialize it for something in particular
@thheller got all that. I've got a full replum repl running in the webworker with libraries loaded.
I guess if you've already defined all your functions, you can just call a look up table on the worker side
in many instances that is more expensive than just not using a worker in the first place
Hi, I am trying to do a simple function check using spec in ClojureScript (:require [cljs.spec :as s] [cljs.spec.test :as test]... (defn my-index-of "Returns the index at which search appears in source" [source search] (clojure.string/index-of source search)) (s/fdef my-index-of :args (s/cat :source string? :search string?) :ret nat-int? :fn #(<= (:ret %) (-> % :args :source count))) and (test/check 'my-index-of) instead of returning a problem , always returns [] meaning basically that it doesn't do anything?
I am basically trying this in ClojureScript https://www.youtube.com/watch?v=W6crrbF7s2s
Hi, I also have a spec
question, is there any way to add a humain friendly message to a spec when failing ?
@baptiste-from-paris https://clojurians.slack.com/archives/C1B1BB2Q3/p1489948793180526
i have a problem deploying.
everything runs fine in figwheel but the release build throws an Error: [object Object] is not ISeqable
...
:dependencies [[org.clojure/clojure "1.8.0" :scope "provided"]
[org.clojure/clojurescript "1.9.229" :scope "provided"]
[reagent "0.6.0"]
[org.clojure/data.xml "0.2.0-alpha2"]]
do i maybe need to include some external js?my lein build profile:
{:source-paths ["src" "env/prod/cljs"]
:compiler
{:output-to "public/js/app.js"
:output-dir "public/js/release"
:asset-path "js/out"
:source-map false
:optimizations :advanced
:pretty-print false}}}}
Is there any reason not to have clj/cljs/cljc files containing the same namespace? For example lib.clj + lib+cljc + lib.cljs
since it’s possibly ambiguous (to someone looking at the codebase) which file you want lib.cljs
to load for macros - I think .clj
gets precedence?
@timrichardt Looks like you're trying to perform a sequence operation on a javascript object.
@janetacarr indeed, the whole thing is related to the externs stuff. i have to spend some time reading how the compiler works... 🙂
with :optimizations :simple
it works
I’ve run this code through an extern generator, but it doesn’t generate one for a function named clearAll
in the React Virtualized library
Generator:
http://jmmk.github.io/javascript-externs-generator/
Loaded JavaScripts:
* https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-with-addons.js
* https://cdnjs.cloudflare.com/ajax/libs/react-virtualized/9.0.3/react-virtualized.js
@borkdude I think react-virtualized does some dynamic magic to add those methods the the class
You can search for clearAll in the JS file to find some suspicious code where methods are defined as array of JS objects
@juhoteperi What’s the recommended way for cljsjs to add something manually to a generated extern file?
@borkdude Just manually edit the code and add a comment to the top of the file that it has been modified manually
return (0, _createClass3.default)(CellMeasurerCache, [ {
key: "clear",
value: function(rowIndex, columnIndex) {
var key = this._keyMapper(rowIndex, columnIndex);
delete this._cellHeightCache[key], delete this._cellWidthCache[key];
}
}, {
key: "clearAll",
value: function() {
this._cellHeightCache = {}, this._cellWidthCache = {};
}
TypeScript has type definitions for react-virtualized (and hundreds of other libraries): https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/react-virtualized/index.d.ts
It is on my todo list to write tool to convert typescript definitions to Closure externs
@juhoteperi I think this is a ES6 construct? https://github.com/bvaughn/react-virtualized/blob/ed887bb8e7141ac04081d50fa6b1f22fde429bf3/source/CellMeasurer/CellMeasurerCache.js#L129
@borkdude it’s just a normal class
CellMeasurerCache.prototype.clearAll = function () {}
@anmonteiro Problem is that in webpack output it is not, so extern generator doesn't find it
yeah, I’m saying for the extern stuff
sorry, meant for writing the manual extern
should work if you write that, right?
there you go, that’s all I’m saying
wow, ((gobject/get “clear”) 0 0)
instead of (.clear cache 0 0)
doesn’t even work because of this
being the wrong value?
Uncaught TypeError: this._keyMapper is not a function
btw. cljs-oops does “this retargeting” for you: https://github.com/binaryage/cljs-oops/releases/tag/v0.5.0
I see here that the author doesn’t use it: https://github.com/binaryage/cljs-oops#integrate-with-your-project
@borkdude it’s not needed because the .cljs
namespace self-requires them https://github.com/binaryage/cljs-oops/blob/master/src/lib/oops/core.cljs#L14
so the CLJS compiler can infer them automatically
magic here: https://github.com/binaryage/cljs-oops/blob/master/src/lib/oops/core.cljs#L14
I just recently discovered that this can be used to avoid writing reader conditionals when requiring macros from cljc files - for code targeting both clojure and clojurescript: https://github.com/binaryage/env-config/blob/master/src/lib/env_config/impl/macros.cljs
and inside macro, I can decide what kind of code I want to generate, depending on current environment: https://github.com/binaryage/env-config/blob/master/src/lib/env_config/impl/macros.clj#L20
usage here: https://github.com/binaryage/env-config/blob/master/src/lib/env_config/impl/coercers.cljc#L4
abarylko what is your :aot setting in project.clj?
if it’s not present, compile won’t output anything
you could try lein compile :all
@noisesmith won't @abarylko want to switch to cljsbuild?
@abarylko I'm guessing not. But if my memory serves, cljsbuild will compile cljc files as well.
most cljs consumers of your library will be using cljsbuild though. So it couldn't hurt to test with it.
hello guys, is there a way to resolve
a symbol in cljs
and then apply the function with the Var ?
Thanks @john & @noisesmith I'll try it out ....
@baptiste-from-paris only from a macro
yep, I just saw that
@mikepence reagent
, re-frame
, quiescent
, om
I probably would suck at summarizing, but:
* reagent
= thin wrapper over react
that just makes it more "cljs idiomatic” to use (not so OO). slightly “opinionated” (I guess) in its usage of RAtom (cljs atom
wrapper)
* re-frame
= larger “framework” that uses reagent
but also pulls together more libs to do things like routing, etc
* quiesent
= sort of like reagent
with a few different goals in mind (good readme there), tries to be very “un-opionated"
* om
= another wrapper over react
, more “opinionated" than others perhaps and was started(?) by David Nolen (lead cljs contributor)
I’m sure others could correct me on a bunch of that. However, all these projects seem to have pretty good docs.
after trying to create a macro that updates the meta data of a function, based on examples here: https://cljs.github.io/api/cljs.core/defn- and here: https://stackoverflow.com/questions/9177709/constant-definition-in-clojure
@john an example of your macro would be helpful
I’ve done that before and it worked
also, do you want the metadata on the function or on the var?
@anmonteiro just going with the defn- example:
(defmacro defn- [name & decls] (list* `defn (with-meta name (assoc (meta name) :private true)) decls))
If I put that in my macros.cljc file, it will run from the repl, the result has no attached metadata
so you should be seeing your metadata on the var
(my-def my-name …)
(meta #‘my-name)
@anmonteiro I'm not sure if I'd be better off working with the metadata of the fn or the var.
@anmonteiro that was it!
Vars are static, so you’ll need to always have the name of the function at hand (i.e. can't get a function via a param and expect it to have metadata)
if you put the metadata on the function, you can call meta on the actual function value, which means the above use case will work
on the other hand, it’s not a JS function anymore, but a JS instance that implements IFn
tradeoffs...
the var
(defmacro defn- [name & decls (with-meta (list* `defn name decls) (assoc (meta name) :private true))])
kinda
you’ll probably want (def symbol (with-meta (fn …)))
defn
may return the function, or the var, depending if you’re in the REPL or not
Okay, so I'm getting close. But for some reason the metadata is dropping key-vals selectively:
(defmacro defn-with-source [name bindings & forms]
`(def ~name
(with-meta `(fn bindings [email protected])
(assoc (meta name)
:const true
:source true))))
@john what are you going to build? some kind of dev tool? wonder why do you need fn sources, just curious