Fork me on GitHub
#clojurescript
<
2019-01-18
>
Kelly Innes02:01:05

Is there a good tutorial for using spec in ClojureScript?

Kelly Innes02:01:00

I'm trying to use it in a Reagent/Figwheel/Expo application and would like to see some examples of other uses.

mfikes02:01:30

@kinnes In general, the ClojureScript implementation of Spec adheres very closely to that of Clojure, so any Clojure tutorial should apply as well.

Kelly Innes02:01:14

Okay, cool -- is https://clojure.org/guides/spec sort of the best source of truth for how to use it?

mfikes02:01:37

Definitely

sekao03:01:02

before i bother filing a bug…is it a known issue that protocol method names cannot clash with javascript reserved words like delete? it’s understandable that it doesn’t work but the error only happens when you try calling the method, and all it says is Cannot read property 'object' of undefined. no me gusta.

mfikes04:01:01

@sekao I don't recall a JIRA like that. I tried, but can't repro: https://gist.github.com/mfikes/f8f1367bc55842a2c7fe4a08d0231c7b

sekao04:01:54

i should’ve mentioned i’m using extend-type. (extend-type default IFoo (delete [_]))

mfikes04:01:18

Hrm.

cljs.user=> (extend-type default IFoo (delete [_] 1))
nil
cljs.user=> (delete #js {})
1

sekao04:01:59

are you sure that isn’t a behavior difference with whatever repl you’re using? here’s what my file looks like:

mfikes04:01:53

Ahh... oops. For that last test I was using something off either master or a patch... I can repro with 1.10.439. So there's hope. 🙂 Let me see if things works master.

mfikes04:01:00

Yeah, master appears to be fixed.

sekao04:01:41

ah! good to know, thanks

mfikes04:01:10

Interestingly, the fix was evidently a side effect of this patch (according to git bisect): https://github.com/clojure/clojurescript/commit/23ab9a095599446e3c2aa5013d2b8edf2bbe467f

ikitommi06:01:46

There was some discussion about #reitit yesterday - I updated the example reagent app to use clojure.spec coercion instead of schema, found here: https://github.com/metosin/reitit/blob/master/examples/frontend/src/frontend/core.cljs. The example also has the documented how to switch to use HistoryAPI. For backend... reitit has built-in modules for ring, pedestal and sieppari. It could be used with #yada too, but the coercion is part of the endpoint data model, which overlaps with yada resources, so the spec coercion with yada would need some extra integration to work.

👍 5
Empperi08:01:13

I wonder if there is a way to limit the amount of dates available in reagent-forms datepicker? Use case: date range selection, one should not be able to select end date which is before the start date. I can of course prevent this via checking the selected value afterwards but it would be more user friendly if those dates were not selectable in the first place. Can't see a way to do this, ideas?

Saikyun13:01:43

hello, I'm going insane trying to get atom (proto repl) + lein-figwheel or figheel-main working, are there any guides for this? I've tried all I could find by googling

WhoNeedszZz22:01:21

It's a hot mess right now. Save yourself the headaches and check out shadow-cljs

Saikyun08:01:11

okay, thanks for the tip. I'll check it out

Saikyun13:01:42

I was happy that atom seemed like a good editor to recommend to newcomers, but not being able to develop clojurescript is kind of bad 😞

borkdude13:01:37

@saikyun fwiw, I mostly rely on hot reloading instead of a REPL for CLJS

Saikyun13:01:12

@borkdude but don't you miss being able to eval-last-sexp etc?

Saikyun13:01:27

and inspecting data etc

martinklepsch13:01:36

@saikyun for some things you would probably be faster with a REPL but the feedback loop of instant reloads is so quick that in many situations it's not much different than using a REPL. Also consider that you might often work on something more visual that would be hard to inspect in a REPL as well.

borkdude13:01:16

@saikyun not really. I sometimes def something so I can inspect in in the browser console with cljs-dev-tools

borkdude13:01:41

I also use a lot of (.log js/console the-thing)

borkdude13:01:04

and re-frame-10x or re-frisk also helps

Saikyun13:01:15

all right, good to know. thanks for your input

Saikyun13:01:39

I use the repl a lot to look at maps, but using js/console makes sense

martinklepsch13:01:30

With cljs-devtools it's nicer than in a REPL (for plain "looking at things" at least)

Saikyun13:01:48

sounds great 🙂 does it work with internet explorer 😉

Saikyun13:01:58

working in a pretty locked down environment

martinklepsch14:01:37

It only works in Chrome I'm afraid

borkdude14:01:37

@saikyun no. but you can also do [:pre (with-out-str (clojure.pprint/pprint the-map))] if you’re using reagent

Saikyun14:01:49

okay thanks 🙂 we plan on trying out reagent

john15:01:46

Yeah, I just use atom with a console repl. Hot reload on save and then do any repling stuff I want to in the console.

Jacob Haag18:01:56

Would anyone know how I achieve modules.export with clojurescript?

// tools.js
// ========
module.exports = {
  foo: function () {
    // whatever
  },
  bar: function () {
    // whatever
  }
};

var zemba = function () {
}
Essentially I have a function that I am exporting in clojurescript
(defn ^:export add-numbers [a b]
  (+ a b))
And I'd like to wrap it with modules.exports

lilactown18:01:38

@jacobhaag17 some build tools handle this for you. what build tool are you using?

lilactown18:01:47

it sounds like you're in a Node.js environment?

Jacob Haag18:01:12

Yup, I am using node.js as my environment

Jacob Haag18:01:32

Essentially I want to access an exported function in another js file

lilactown18:01:17

are you using shadow-cljs?

Jacob Haag18:01:49

leiningen and cljsbuild

lilactown18:01:25

even if you're not using figwheel, that's how you'll do it

Jacob Haag18:01:45

Cooleo, thanks much @lilactown

Pavel Klavík18:01:11

Hi, I am building a full stack web app and currently using lein and cljsbuild for compilation. (Based on reframe lein template.) I am thinking of switching to shadowcljs for npm support. What is the workflow for web server compilation, to produce uberjar?

cjohansen21:01:39

does anyone have any pointers to deploying ClojureScript libraries to clojars with tools.deps? I did clojure -Spom and mvn deploy, but it only put an ~empty jar in clojars (no sources)

Alex Miller (Clojure team)21:01:26

there are some packaging/deployment tools in https://github.com/clojure/tools.deps.alpha/wiki/Tools although they are mostly oriented toward clojure code, not sure if they will do what you need for cljs

cjohansen21:01:02

yeah, I was looking at pack, but honestly I don't even know what it takes to publish a cljs package to clojars 😕 always used lein in the past, and now I know nothing of what it really did

cjohansen21:01:10

looks like I can generate a pom and jar, and then try mvn deploy. I'll tinker around a little 🙂