Fork me on GitHub
#clojurescript
<
2020-01-14
>
andy.fingerhut07:01:30

In Clojure/Java, there are functions extenders and extends? in clojure.core that can in some cases let one know whether an object or type/class extends a particular given protocol. These do not exist in Clojurescript, at least not by those names. This is not high priority by any means, but is there perhaps data that one can peek/poke/prod at at a Node.js REPL (or some other JS runtime REPL) that let you discover that information in a running system?

andy.fingerhut10:01:12

I don't know. I can try it out and see what it does.

andy.fingerhut07:01:59

I know one can examine the ClojureScript source code, of course. I was curious if there was a more dynamic way to do it, like there is in Clojure/Java.

thheller09:01:18

@andy.fingerhut not quite sure what you are asking. there is (satisfies? SomeProtocol foo) or (implements? SomeProtocol foo)?

dabrazhe10:01:40

Hi. Can someone help with AWS sdk response from nodes,js aws-sdk. I would like to return in aws labmda cljs function I am getting an [Object etc] as a response which I cannot seem to be able to pass it to the lambda handler callback, (if I print it, I can see the data). The AWS SDK node.js documentation suggest using a promise var bucketPromise = new AWS.S3({apiVersion: '2006-03-01'}).createBucket({Bucket: bucketName}).promise(); Promise would work for me. How can I achieve this in cljs? And is the the best way to handle it?

valtteri12:01:06

@dennisa something like this

(ns myns.core
  (:require
   ["aws-sdk" :as AWS])

(def s3 (new AWS/S3))

(-> s3 
  (.createBucket #js{:Bucket "blabla"})
  (.promise))

valtteri12:01:27

Threaded expression will return a promise that you can return from the lambda handler function

valtteri12:01:22

You can either return a promise from the lambda handler, or call the callback function. If you want to do the latter you can do something like

(-> s3 
  (.createBucket #js{:Bucket "blabla"})
  .promise
  (.then callback))

valtteri12:01:30

Where callback is the Lambda callback function

valtteri12:01:07

Here’s a small example project where I’m using node aws-sdk with lambda https://github.com/vharmain/serverless-healthcheck/blob/master/src/healthcheck/core.cljs

dabrazhe13:01:39

@valtteri This is exactly what I was looking for, this works fine when is invoke the function locally:

(-> my-s3-client
                   (.listBuckets)
                   (.promise)
                   (.then (fn [res]
                            (print res)
                            (clj->js res)))))

dabrazhe13:01:38

Do you perhaps know how to return a value from a chan into aws lambda callback in cljs? This is puzzling me because go block is returning a channel and breaks lambda. Perhaps some trick with take! ?

darwin14:01:33

not sure if I understand it correctly, but typically you want to convert callbacks to core-async channels, the idea is to return a channel and do put! in callback body (to convert callback call into a new item on channel)

darwin14:01:15

btw. promise-chan is better thatn general chan because you know it will be just one-off callback

valtteri14:01:22

Sorry I’m not using core.async in lambdas, just Promises.

thanks2 4
dabrazhe16:01:31

@darwin The callback I am talking about is the AWS lambda callback mechanism in the handler. I can either return a promise in the handler (which is covered by example above) or call the callback, which should return the final result. When I call callback in take! it looks like the handler fails on no value:

(.listBuckets my-s3-client    #(put-in-chan ch %2 :Buckets))
  (defn handler [event context callback]
  (take! ch #(callback nil #js{:statusCode 200
                               :headers #js{"Access-Control-Allow-Origin" "*"
                                            :Content-Type "text/html"}
                               :body (str %)})))

ShaneLester18:01:58

Anyone have any successful usage of material-ui/pickers and date-io/moment in their stuff? Currently attempting to use these by importing like

["@material-ui/pickers" :refer [DatePicker MuiPickersUtilsProvider]]
["@date-io/moment" :default MomentUtils]
and it seems that the import of DatePicker and MuiPickersUtilsProvider work, but my import of MomentUtils seems to be undefined when I try to use it. Any ideas on stuff to try?

valtteri18:01:53

@shanelester55 try this ["@date-io/moment" :as MomentUtils]

ShaneLester18:01:47

Ha. now it works perfect. Thank you @valtteri

valtteri18:01:58

No problem!

otwieracz21:01:03

I've got Pathom related question. I am trying to create global resolver, but by some reason I am constantly getting not found response. First, I have wire-list . Take this sample query:

[{[:wire-list/id :my-wires] [:wire-list/id :wire-list/wires]}]
it return:
{[:wire-list/id :my-wires]
 {:wire-list/id :my-wires,
  :wire-list/wires [{:wire/id 0} {:wire/id 1}]}}
as expected. However, when I try to use resolver:
(defresolver wires-resolvers [_env _input]
  {::pc/output [{:wires [:wire-list/id]}]}
  {:wires {:wire-list/id :my-wires}})
like
[{:wires [:wire-list/id]}]
I am getting:
{:wires {}}
in response

otwieracz21:01:48

What am I doing wrong?

dpsutton22:01:45

in (def foo x/bar) is there an easy way to have x/bar's metadata on foo? Have a util namespace for some components and this would be quite a nice usability improvement

bfabry22:01:58

depends what you mean by easy I guess. (alter-meta! #'foo merge (meta #'x/bar)) directly after isn't super hard, but it's definitely not nothing

bfabry22:01:05

not available to anything indexing the codebase statically too

dpsutton23:01:46

yeah. any of this would fail clojure-lsp usage so its a no-go for my vim/clojure-lsp bound coworkers

p-himik08:01:02

In this case, making the LSP understand alter-meta! is probably the only way .