Fork me on GitHub
#clojurescript
<
2018-11-11
>
Joel Elkins00:11:45

I'm doing an ajax call that returns a BigInt, which gets translated by transit into cognitect.transit.BigInt on the cljs side. What can I do with that? Coercing to a string would be fine but how?

mfikes01:11:26

@joel032 if bigint is a BigInt, then (.-rep bigint) will evaluate to its string representation

attentive07:11:11

What's the state of the art for interacting with Promises currently? I'm open to the method described at this link (which I think could be made cleaner with helpers for specific uses) but it'd be nice to get a second opinion https://blog.jeaye.com/2017/09/30/clojurescript-promesa/

didibus07:11:51

Promesa is pretty nice, but it works with bluebird promises, not native JS promises.

4
didibus07:11:05

I don't know of anything like it that works with native promises though

attentive07:11:06

Yeah, it's the littering of js/Promise.resolve through code taking that approach (which I've used myself in a couple of places in a current project) that's unappealing

borkdude10:11:08

anyone running into problems with secretary on cljs 1.10.439, it now lives on in https://github.com/clj-commons/secretary

rastandy11:11:19

Hello everyone, is there a clojurescript library for accessing the DynamoDB API? I’ve found hildebrand is not developed anymore

valtteri15:11:32

Hello @rastandy! I’m not aware of Clojurescript library but I recommend using the official AWS Node.js SDK via interop. The SDK supports Promises and you get nice ergonomics with Promesa library. Here’s a small example with SNS but it would be similar with DynamoDB.

(ns example.core
  (:require [cljs.nodejs :as nodejs]
            [promesa.core :as p]))

(def AWS (nodejs/require "aws-sdk"))
(def sns (new AWS.SNS))

(def params #js{:Message     "some message"
                :PhoneNumber "+123456789"})

(-> sns
    (.publish params)
    .promise
    (p/then (fn [resp] {:result resp})))

rastandy15:11:41

@valtteri Thank you very much, I think I will follow your recommendation, the code seems clean enough with the Promesa library

👍 4
valtteri15:11:04

Pro tip: Promesa uses Bluebird promises under the hood. You can tell AWS-SDK to also use Bluebird instead of native JS promises. It works also with native promises, but you get better performance and some advanced features with Bluebird. If you’re interested see “Setting Promise Library” section https://aws.amazon.com/blogs/developer/support-for-promises-in-the-sdk/

borkdude15:11:37

why isn’t nil reduceable? in cljs?

(clojure.core/reduceable? nil)

borkdude15:11:14

also these ones:

cljs.user=> (iterable? nil)
false
cljs.user=> (seqable? nil)
true

mfikes16:11:41

seqable? matches Clojure behavior for nil

mfikes16:11:26

cloneable? seems to fall into the same category as reduceable? and iterable? (ClojureScript-specific protocol tests, without implying any further semantics)

mfikes16:11:27

The return values for each seem to match what happens with nil:

cljs.user=> (-clone nil)
No protocol method ICloneable.-clone defined for type null:
	cljs.core/missing-protocol (cljs/core.cljs:316:4)
	cljs.core/-clone (cljs/core.cljs:567:17)

cljs.user=> (-reduce nil +)
No protocol method IReduce.-reduce defined for type null:
	cljs.core/missing-protocol (cljs/core.cljs:316:4)
	cljs.core/-reduce (cljs/core.cljs:692:4)

cljs.user=> (-iterator nil)
No protocol method IIterable.-iterator defined for type null:
	cljs.core/missing-protocol (cljs/core.cljs:316:4)
	cljs.core/-iterator (cljs/core.cljs:867:15)

mfikes16:11:03

The answer can also depend on runtime:

cljs.user=> (extend-type nil ICloneable (-clone [_] 1))
nil
cljs.user=> (cloneable? nil)
true
cljs.user=> (clone nil)
1

Roman Tsopin18:11:59

Hi all, is there way to start cljs.main REPL with electron target? The problem is it has something from browser and something from node. Can’t figure it out how to mix it

lilactown18:11:35

@romantsopin there’s a few Electron starter git repos floating around. I don’t know how up-to-date they are

mfikes18:11:07

It would involve two separate REPLs, right?

lilactown18:11:21

yes, it looks like they have separate builds and REPLs for the node side vs browser side

lilactown18:11:20

you’d need to have a build/REPL for the “main” process” and another for the “renderer” process

lilactown18:11:31

seems simple enough

Roman Tsopin19:11:50

I have a problem with renderer side, it’s mostly like a browser but it uses some node stuff too, for example file system and I don’t know how to require electron from browser side properly

Roman Tsopin19:11:39

I mean, it’s all good when I just “watch” the file, but when I try to start REPL - it expects me to launch browser and browser fails on node part

mfikes19:11:30

Oh, right...

mfikes19:11:50

So, there is a way to suppress automatic browser launch if you are using the browser REPL

Roman Tsopin19:11:43

Yep, but then it’s waiting for manual launch on the expected port

mfikes19:11:47

But I wonder if electron will connect to your REPL. Hmm. Here is the option https://clojurescript.org/reference/repl-options#launch-browser

mfikes19:11:31

Right. I don't understand the electron model well enough. I've used Electron with Figwheel in that case, but it ends up making an altogether different connection.

Roman Tsopin19:11:57

Yes, if I could somehow connect to electron directly, but can’t figure out the proper way to do it. Thanks, will look at Figwheel. Just wanted to get simplified model first

iha222:11:04

Has anyone else noticed that number? return true for ##NaN?

Alex Miller (Clojure team)22:11:42

technically, NaN is a “special” number value, but it’s best not to think too hard about it

iha222:11:06

Indeed. What is the recommended way to check for strictly real numbers then?

mfikes22:11:20

(js/isNaN ##NaN) could be used to form a solution

mfikes22:11:43

infinite? is another useful predicate in this area

mfikes22:11:47

The guts of cljs.pprint/float? looks useful, but I wouldn't require that namespace just for that fn

iha222:11:00

I used (js/isNaN ##NaN). Called it number2?. Thought is was a bad name.

iha222:11:23

I guess I’ll continue to use that.

mfikes23:11:55

real? or finite?. Hmm

frozenlock23:11:09

As posted on IRC : With the new cljs update (1.10.439), I have macros emmitting a warning on private var use (in the same namespace... tho I guess the macros are clj and the rest is cljs...). Should I simply stop using private functions inside macros?

mfikes23:11:35

@frozenlock If there are no perf concerns you can use the var special (or its #' reader equivalent) to access private vars

mfikes23:11:15

If perf is a concern, you can use a bit of a hack to use js interop to access the private var from the macro

mfikes23:11:39

By the way, even though a macro might appear to be accessing a var in its own namespace, I suspect if you look at what is really going on, the macro is being expanded in another namespace, which produces code that accesses the private var; the same issue would occur in Clojure, but the access would be denied there

frozenlock23:11:12

Hmmm the macro works fine in clojure.

frozenlock23:11:22

I'll try to expand it.

mfikes23:11:21

@frozenlock Here is a gist of the example I had in mind, failing in Clojure: https://gist.github.com/mfikes/42063f0840c3f99b0ddfac141c130bac

frozenlock23:11:53

@mfikes Thanks, it does make it clearer.