This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-28
Channels
- # aws (7)
- # beginners (69)
- # boot (67)
- # cider (9)
- # cljs-dev (159)
- # cljsrn (2)
- # clojars (25)
- # clojure (345)
- # clojure-austin (9)
- # clojure-berlin (1)
- # clojure-dusseldorf (10)
- # clojure-italy (3)
- # clojure-nl (1)
- # clojure-portugal (1)
- # clojure-spec (73)
- # clojure-uk (59)
- # clojurescript (163)
- # clojurewerkz (1)
- # component (26)
- # core-matrix (2)
- # cursive (20)
- # datascript (32)
- # datomic (15)
- # dirac (16)
- # emacs (3)
- # hoplon (35)
- # jobs-discuss (87)
- # jobs-rus (95)
- # luminus (15)
- # om (135)
- # om-next (3)
- # onyx (47)
- # pedestal (67)
- # perun (74)
- # play-clj (4)
- # portland-or (1)
- # proton (4)
- # re-frame (13)
- # reagent (18)
- # remote-jobs (17)
- # rum (20)
- # specter (11)
- # untangled (101)
- # yada (18)
I think I'm creating them correctly but one of my subs doesn't seem to exist when I go to use it
the last paragraph of https://github.com/omcljs/om/wiki/DataScript-Integration-Tutorial states: That's all there is to it! Due to its support for Datomic Pull Syntax, DataScript is a natural fit for Om Next applications especially if they do not or cannot have significant remote service integration. Contact GitHub API Training Shop Blog About This seems to imply that for remotes, plain Om Next Db works better than datascript -- what is the reasoning behind this?
Tomorrow I’m having a session with my colleagues on Clojure(Script). Do you have any ideas of what would be cool to present or dabble with?
has someone experience or example code of creating priority queue in clojurescript, like described here? http://jsperf.com/js-priority-queue-queue-dequeue
ok, didn't think about looking there. Of course goog.* should have been my first (latest second) place to look. Well, my question is bit unformulated, I'll explore more before asking again. Thanks.
i have been a career backend programmer (java and clojure). and cljs seems to me like just the right vehicle for me to explore frontend dev. i’ve never done any html/css/js work. anyone here got advice for what’s the bare minimum learning of html/css/js I need before i can start using cljs to build decent frontends. i’d like to be in a position where i use cljs for everything and step into html/css/js only if i have to. how do i go about my journey, any learning resources you’d like to point to if you’ve gone through a similar journey. thanks for your time!
@moizsj you could do worse than start with a template, like https://github.com/martinklepsch/tenzing , perhaps use it to initialise a basic reagent or rum app and kick its tyres
@U0524B4UW thats an eye opener. #nobackend sounds fab
@moizsj I was in a similar position. I'd say HTML isn't the hard part, but CSS is. (Especially the box model etc). The spec is actually really good and has tons of examples as well. For example:
, better than most online tutorials.
@moizsj I'm i nthe opposite situation and from what I know of clojurescript you still need to know the names of native js functions, and yeah css can be a pain sometimes
Is there anything against dynamically requiring a namespace in clojurescript, e.g. are we missing out on some advanced compiler feature there?
dead code elimination among others I’m sure
(defmacro require* [ns-prefix]
(let [namespaces
(map #(symbol (str ns-prefix "." %))
["views" "events" "subs" "db"])]
(cons 'do
(map (fn [ns]
(list 'require `(quote ~ns)))
namespaces))))
@borkdude I don't think that is dynamic require though...that's just a macro that emits a require
Don't think so (unless there's something about CLJS's require outside of a ns I don't know)
But I have to ask "why?"
Macros like that will break tools, and make the code harder to understand
If those things are always going to be used together, why not just put them in the same namespace?
@hjkels Definitely use figwheel. Perhaps a simple example relevant to the business you are in would be the best thing to convince people that ClojureScript is worth using.
@bronsa it was added recently 😕 with the restriction that it must be a top level form, essentially modifying the ns
form
@tbaldridge Good point. Why not put those namespaces together? Well, shorter files are sometimes easier to work with and it’s a standard structure of re-frame apps I believe
@tbaldridge This is used in some initial namespace where we have a map of keywords to pages/components
@borkdude that's not gonna work
@anmonteiro Explain?
Try requiring a namespace not required anywhere else in your project, and the compiler won't be able to find/sort deps
This has nothing to do with optimizations
It's about ClojureScript's compilation model
@borkdude I had been wondering about that. They use a similar concept in Phoenix, where you have a place you can specify a set of requires/imports, then pull a group of those in with one call. Works out quite well for views/controllers - standard things that you need a lot of
@borkdude sorry was on phone, I can expand on my reasoning now. Basically the way we compute dependencies in the ClojureScript compiler is we analyze just enough of either a namespace declaration or a set of requires
this is why they need to be at the top of the file - to prevent us from analyzing the entire thing and slowing down compilation
they also need to be static, due to Closure Compiler requirements
remember that dynamic require and whole program optimization are not particularly compatible things
@borkdude so your macro would probably work fine if it sit at the top of a file (which has no NS declaration)
but that’s not particularly useful, is it?
i spent the last 4 minutes trying to think of a reason why i would need dynamic requires
@borkdude now I can imagine why you’d want to require things dynamically
you wanna ship the least amount of code possible in a first route, and async load dependencies based on some heuristic
the Closure Compiler supports this via Closure modules
so if that was your goal, it is possible, just not with require
@isak as @anmonteiro mentioned you’re probably talking about code splitting
@dnolen no, @borkdude was trying to think of a way to reduce boilerplate in ns
forms, i was just showing some prior art
@borkdude if you were actually looking for how to do code splitting this is a good primer https://rasterize.io/blog/cljs-dynamic-module-loading.html
I’m not looking for code splitting, just eliminate some boilerplate because a colleague asked for it. Not a major issue.
He was referring to this though, not sure if that is relevant here? http://stackoverflow.com/a/30171851/6264
if you have namespaces that are always needing the same namespaces, you might have a code structure problem
and writing a macro to solve it is going to hurt
yeah that’s what I figured, we ended up with this due to re-frame where each “page” has a db, events, subs, and views namespace
but that means every page has 4 namespaces that need to be included in the “main” file each time we add one
which is tedious and error prone, just looking for a way to restructure it
then I remembered the trick cljs.test uses, but I guess that will break things
guess we’ll have to rethink it, anyone with a large-isch re-frame app that can give insight into how they do it 😉 ?
This is just the namespace structure re-frame suggests: https://github.com/Day8/re-frame/tree/master/examples/todomvc/src/todomvc
that’s a good point, not sure why re-frame proposed this, we were just following the example as @borkdude says
we could just squash them all into one namespace, files would be significantly longer, but that might be a trade-off to consider
definitely sounds easier to reason about your code if every thing that belongs to the component’s behavior is co-located with the component definition
but I’m probably biased when it comes to co-location 🙂
I guess the re-frame decision comes more or less from the MVC model, where the M, V, C have different files
but re-frame is not really about MVC AFAICT
true, but just saying that’s probably where the file layout comes from
its just a standard thing in a lot of frameworks/libraries across languages - separate things out into tons of files. A little less convenient in clojure than other langs, but not a huge deal. Can combine things of course, but it isn't an obvious improvement, other than the import stuff
The reason we need to require the subs and events namespaces are because they are decoupled in re-frame: you don’t need to require a namespace to be able to dispatch an event, but you have to load the namespace at some point of course. We could merge everything related to one page/component in one file, but I’m not sure if that’s easier to work with.
@joelkuiper: For re-frame development, the structure is really flexible - you can do it as in the todomvc, put your whole project in one file, or split components up into their own file - it really doesn't matter as far as functionality. My general approach has been to start with one file for each "section", and then refactor into separate namespaces as it fits your application. There's not any real refactoring support outside of find and replace, but if you are using uniquely named elements with namespaces that make sense to you it's pretty straightforward.
As I’m using re-frame now, I have one ‘main’ file, and one for each page, I don’t really see the point in breaking it up even further for components, or for each layer of a component
The structure in the todomvc app is pretty well suited for an application where each of your "sections" is a reasonably complex application in itself - not great for components though. But one of the very nice things about re-frame is that it makes very few decisions for you outside of the essential trade-offs that come with it. If you want to go into detail on your specifics we can take it to the #re-frame channel as well.
@mruzekw does not
I'm trying to translate a JS example to CLJS for OpenLayers, which uses Google Closure, and I suspect I'm doing something wrong with my require
or import
- the generated JS code works when pasted in to the original example but the CLJS is giving me an error. Apologies for the length, code snippets don't seem to be working.
(ns hello-world.core
(:require [ol.proj]
[ol.layer.Tile]
[ol.source.OSM])
(:import [ol.Map]
[ol.View]))
(def my-map
(ol.Map. #js {"target" "map"
"layers" #js [(ol.layer.Tile. #js {"source" (ol.source.OSM.)})]
"view" (ol.View. #js {"center" (.fromLonLat ol.proj #js [37.41 8.82])
"zoom" 4})}))
Error Message Uncaught TypeError: Cannot read property 'getExtent' of null at Object.ol.tilegrid.extentFromProjection (tilegrid.js:149) at [as constructor] (xyz.js:37) at new ol.source.OSM (osm.js:34) at core.cljs:11
Any ideas? Original JS example can be found at https://openlayers.org/en/latest/doc/quickstart.html@shaun-mahood just looks like you’re not import
ing enough stuff
e.g. ol.layer.Tile
and ol.source.OSM
@shaun-mahood actually is looks like there’s more stuff wrong with your example
you’re using a namespace as if it were an object?
(.fromLonLat ol.proj #js [37.41 8.82])
?
I don’t think this will mean anything to CLJS
you actually want ol.proj/fromLonLat
there, for example
just like when you require goog.string
and you use goog.string/includes
or something
On the import vs require question, my understanding is a bit vague there - based on how it's used and the API definituon at https://openlayers.org/en/latest/apidoc/ol.layer.Tile.html I expected it to require an import
, but if I move it from require
to import
I get the error Uncaught TypeError: Cannot read property 'Tile' of undefined
- I don't need to have it in both, do I?
@shaun-mahood the rule of thumb is, require namespaces, import objects classes
you probably need to (require ol.layer)
and then import ol.layer.Tile
They don't seem to actually have an ol.layer
namespace...
I'm writing a command-line utility using ClojureScript and targeting Node as the runtime. I have a few dependencies that I’m pulling in from npm. Is it possible to compile my application into one js file using :optimizations :advanced and have it pull the npm dependencies into that one js file as well? So far, it doesn’t seem like that’s the case but maybe I’m doing something wrong.
it probably relies on s3 🙂
i think i’ve read that page though
is it about how google closure now understands nodejs modules?
ahh ok
so there is a path to doing this. that’s good news
hey guys, if I want to have a namespace called test-helpers
, I can’t seem to be able to put it in ../test/cljs/my-proj folder? even if it’s added to :source-paths
?
@ag you just need to follow the directory structure. if it’s a single segment namespace it needs to be at the root of the classpath
@jr thank you, btw
the javascript-modules page is up. i’m going to walk through the example now
@jaydeesimon hopefully what you’re trying to achieve will be even easier in the very short term http://dev.clojure.org/jira/browse/CLJS-1960
whoa that would be so sweet
i’ve just started to play around with clojurescript on nodejs and i am amazed by the possibilites
the patch implements what is detailed in this page https://github.com/clojure/clojurescript/wiki/Enhanced-Node.js-Modules-Support
@anmonteiro: I think I've narrowed down the code to an obvious difference. The JS code var projections = ol.proj.projections.cache_
returns null in my CLJS version - I think I'm going to try and make an intermediate version which is JS using the Closure Compiler since my grasp of how it works is pretty shaky. Thanks for the help!
i’m surprised i don’t see more clojurescript+node apps
is this the right opts construct for clojure.spec.test/check in clojurescript?
(stest/check `specced-fn {:clojure.spec.test.check/opts {:num-tests 1}})
I think it’s slightly different (s/clojure/cljs) ?
ok ... i wasn't sure because
(:require [clojure.spec :as s])
magically works in clojurescriptI’m not positive tbh
@tankthinks we auto-alias namespaces not keywords
@tankthinks I think @alexmiller is right. you can use ::stest/opts
and it’ll work
sorry I’m wrong above. needs to be cljs.
...
so
(stest/check `specced-fn {:cljs.spec.test.check/opts {:num-tests 1}})
@tankthinks OK found your issue
clojure.test.check/opts
, not clojure.spec.test.check/opts
oh, yeah. sorry I didn’t see that.
ah ... thank you!!!
from the docstring:
The opts map includes the following optional keys, where stc
aliases clojure.test.check:
::stc/opts opts to flow through test.check/quick-check
the clojure docstring is:
The opts map includes the following optional keys, where stc
aliases clojure.spec.test.check:
https://clojure.github.io/clojure/branch-master/clojure.spec-api.html#clojure.spec.test/check
@tankthinks that’s the difference between Clojure and ClojureScript
we cannot do this in CLJS: https://github.com/clojure/clojure/blob/master/src/clj/clojure/spec/test.clj#L17-L19
thanks ... i was working in a cljc file so was using the clojure docs ... everything has magically worked in clojurescript, which is amazing! thanks for the heads up
Hey friends, got a question regarding JS interop and the compiler. My CLJS needs to call:
(js/window.webkit.messageHandlers.authStatus.postMessage status)
but when it’s optimized :advanced I get:
window.webkit.messageHandlers.vq.postMessage()
@campeterson add an extern, e.g.:
var webkit = {};
webkit.messageHandlers = {};
webkit.messageHandlers.authStatus = {};
webkit.messageHandlers.authStatus.postMessage = function(msg) {};
@anmonteiro Thanks. will give it a go
or (gcall “window.webkit.messageHandlers.authStatus.postMessage” status)
with cljs-oops:
https://github.com/binaryage/cljs-oops
Hey guys, I'm trying to translate some javascript into clojurescript - does anyone know how to call the |
operator? e.g 2 & 0x3 | 0x8
@mikepjb bit-or
many thanks @anmonteiro