Any pointer to make ClojureScript + JavaScript interop work with promise library?

clojurescript

#1

Hi All,

I am not sure if this is the right place to post

const api = require(‘node-gitlab-api’) ({
   {
     url: ‘https://….’,
     token: ‘…’
   }
})

function js_interops(api) {
   api.projects.all( {max_pages: 1,
                             per_page: 5
                            })
   .then((projects) => {
      for (project of projects) {
        console.log(project)
      }
    }
}

I did the first part like

(def gitlab (js/require "node-gitlab-api" (clj->js {:url "https://gitlab.com"
                                                    :token "<some-token>"
                                                    })))

I am having a problem getting this translate to ClojureScript especially the promise library in ClojureScript in the 2nd part.

Any recommendation on how to best handle this?

Any guide/pointer is greatly appreciated.


#2
(def node-gitlab-api (js/require "node-gitlab-api"))

(def api (node-gitlab-api #js {:url "" :token ""}))

(-> (.all api.projects #js {:max_pages 1 :per_page 5})
    (.then #(doseq [project %]
              (println project))))

One thing I noticed is that there’s for...of iteration which doesn’t seem necessary here, bc most likely projects is just a collection of data. But if it’s really a custom iterable object, then the code might be a bit different.


#3

@roman01la

Thank you so much for this. I did not know it would be so simple.


#4