This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-11
Channels
- # aleph (5)
- # beginners (13)
- # boot (2)
- # cljs-dev (1)
- # clojure (12)
- # clojure-italy (1)
- # clojure-russia (67)
- # clojure-uk (2)
- # clojurescript (49)
- # datomic (1)
- # defnpodcast (3)
- # graphql (8)
- # jobs (1)
- # lein-figwheel (1)
- # leiningen (1)
- # lumo (9)
- # off-topic (5)
- # om (3)
- # parinfer (13)
- # pedestal (2)
- # re-frame (5)
- # reagent (4)
- # ring-swagger (2)
- # untangled (13)
- # yada (2)
(ns guller.macros)
(defmacro then->>
[x & forms]
(loop [x x, forms forms]
(if forms
(let [form (first forms)
threaded (if (seq? form)
`(.then ~x #(~(first form) [email protected](next form) %))
`(.then ~x #(~form %)))]
(recur threaded (next forms)))
x)))
(defmacro then->
[x & forms]
(loop [x x, forms forms]
(if forms
(let [form (first forms)
threaded (if (seq? form)
`(.then ~x #(~(first form) % [email protected](next form)))
`(.then ~x #(~form %)))]
(recur threaded (next forms)))
x)))
(ns guller.core
(:require-macros [guller.macros :refer [then-> then->>]]))
(require '[cljs.pprint :as pp :refer [pprint]])
(def github (js/require "github"))
(def githubapi (github.))
(defn flip
"given a function, create a flipped 2-argument function"
[f]
(fn [a b] (f b a)))
(defn getOrgs
"Get the organisations for an authenticated user"
[]
(then-> (.. githubapi -users (getOrgs {}))
(js->clj :keywordize-keys true)
:data
((flip map) :login)))
(defn getReposForOrg
"Get all the repos for an Org"
[org]
(then-> (.. githubapi -repos (getForOrg #js {:org org}))
(js->clj :keywordize-keys true)
:data
((flip map) :ssh_url)
pprint))
(defn -main []
(.. githubapi (authenticate #js {:type "netrc"}))
(then->> (getOrgs)
(mapv getReposForOrg)))
Not sure if I prefer the reduce
(see history) version or not as gives more control over the position of the response.
Actually it’s not that good; it works over synchronous call backs i.e., doesn’t actually chain promises. Hmmmmm.
Interesting stuff