1

I'm trying to convert the following JavaScript function definition to ClojureScript to no avail:

chrome.webRequest.onBeforeRequest.addListener(
        callback_function,
        {urls: ["<all_urls>"]},
        ["blocking"]);

Here's the ClojureScript I'm using to try and replicate this:

(defn my-listener
  [data]
  (.log js/console data))

(defn web-request
  [listener]
  (.. js/chrome -webRequest -onBeforeRequest (addListener listener) (clj->js {"urls" ["<all_urls>"]}) (clj->js ["blocking"])))

(web-request my-listener)

It looks like the last 2 pieces to the function declaration aren't being generated properly (the {urls: ["<all_urls>"]}, ["blocking"] bit). Here's what the compiler is outputting from the ClojureScript version:

example.core.my_listener = function example$core$my_listener(data) {
    return console.log(data)
}
;
example.core.web_request = function example$core$web_request(listener) {
    return chrome.webRequest.onBeforeRequest.addListener(listener).clj__GT_js(new cljs.core.PersistentArrayMap(null ,1,["urls", new cljs.core.PersistentVector(null ,1,5,cljs.core.PersistentVector.EMPTY_NODE,["\x3call_urls\x3e"],null )],null )).clj__GT_js(new cljs.core.PersistentVector(null ,1,5,cljs.core.PersistentVector.EMPTY_NODE,["blocking"],null ))
}
;
example.core.web_request.call(null , example.core.my_listener);

Any suggestions would be appreciated. Thanks!

John
  • 3,296
  • 2
  • 24
  • 36

1 Answers1

0

Your addListener method/function/prototype_inheritance_thing is an arity three procedure therefore you have to call it like this:

(defn web-request
  [listener]
  (.. js/chrome -webRequest -onBeforeRequest (addListener listener (clj->js {"urls" ["<all_urls>"]}) (clj->js ["blocking"]))))
Ricardo Acuna
  • 530
  • 2
  • 10