This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-10
Channels
- # aleph (1)
- # beginners (39)
- # boot (14)
- # cider (2)
- # clara (6)
- # cljs-dev (39)
- # cljsrn (2)
- # clojure (276)
- # clojure-italy (1)
- # clojure-russia (22)
- # clojure-sg (2)
- # clojure-spec (7)
- # clojure-uk (9)
- # clojurescript (47)
- # core-async (1)
- # cursive (5)
- # emacs (1)
- # events (3)
- # leiningen (1)
- # luminus (2)
- # lumo (75)
- # om (14)
- # onyx (1)
- # parinfer (11)
- # pedestal (1)
- # ring-swagger (2)
- # spacemacs (4)
- # untangled (5)
- # yada (29)
#!/usr/bin/env lumo
(require '[cljs.pprint :as pp :refer [pprint]])
(def github (js/require "github"))
(def githubapi (github.))
(.. githubapi (authenticate #js {:type "netrc"}))
(-> (.. githubapi -users (getOrgs {}))
(.then #(:data (js->clj % :keywordize-keys true)))
(.then #(map :login %))
(.then #(println %)))
(-> (.. githubapi -users (getOrgs {}))
(.then #(:data (js->clj % :keywordize-keys true)))
(.then #(map :login %))
(.then #(map println %)))
which npm package is that?
"github"?
uses promises (I dont’ know much about node or promises) I’m just playing with Lumo as a script env at the mo.
I get UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: ~/.netrc authentication type chosen but no credentials found for '
how do I do that?
You’d have to create a personal access token in github and then setup the ~/.netrc file
got it to work
replace the map
s with mapv
s
doall should work as well
alternatively, the last one could use run!
instead of map
it works for me then - I get one organization back
what does it print for you with run!
?
(doall (map println %))
also works for me
hehe yeah laziness gets everyone, now and then
btw not sure about the wisdom of those consecutive promises if the steps aren't async
although I've seen this frequently in node code, so not picking on you
I mean you could use a single .then
step no?
I kinda liked the monadic nature of multiple .thens but if that’s not good Clojure style I shall change 🙂
don't know about that, but it just seems pointless to me (in js as well as in cljs)
node programmers in general seem to be seeking asynchrony like the moth seeks the flame... I just don't understand why
interesting idea
although that could encourage the async step where it's not needed I suppose?
all io in node is async, give or take
at least all network io for sure
agree, it's contagious
Was porting a script I use to clone all my repos across all orgs to Lumo as an experiment.
i feel cljs macros could help mitigate the pain, with the right syntax
but not sure what that syntax would look like
#!/usr/bin/env lumo
(require '[cljs.pprint :as pp :refer [pprint]])
(def github (js/require "github"))
(def githubapi (github.))
(defn then->
"Promise threading"
[promise & callbacks]
(reduce (fn [promise callback] (.then promise callback))
promise
callbacks))
(.. githubapi (authenticate #js {:type "netrc"}))
(defn getReposForOrg
"Get all the repos for an Org"
[org]
(then-> (.. githubapi -repos (getForOrg #js {:org org}))
#(:data (js->clj % :keywordize-keys true))
#(map :ssh_url %)
#(pprint %)))
(defn getOrgs
"Get the organisations for an authenticated user"
[]
(then-> (.. githubapi -users (getOrgs {}))
#(:data (js->clj % :keywordize-keys true))
#(map :login %)))
(then-> (getOrgs)
#(mapv getReposForOrg %))
I wonder if it would be difficult to "promisify" callback style code by using a canary for where the callback would go?
^ this will be in the next Lumo
@dominicm https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original
then->
still reads better imho, I like the above
@mattford not sure what problem you’re having but this post may help: http://blog.fikesfarm.com/posts/2015-09-07-messing-with-macros-at-the-repl.html
macros in self-hosted ClojureScript behave a little differently