Use :modules to support a common cljs lib
This commit is contained in:
parent
99ced216df
commit
fcaf8b57d7
@ -14,16 +14,18 @@
|
|||||||
"matches": ["<all_urls>"],
|
"matches": ["<all_urls>"],
|
||||||
"js": [
|
"js": [
|
||||||
"browser-polyfill.min.js",
|
"browser-polyfill.min.js",
|
||||||
|
"out/cljs_base.js",
|
||||||
"content.js"
|
"content.js"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": ["browser-polyfill.min.js", "background.js"]
|
"scripts": ["browser-polyfill.min.js", "out/cljs_base.js", "background.js"]
|
||||||
},
|
},
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
"default_icon": "icons/icon48.png",
|
"default_icon": "icons/icon48.png",
|
||||||
"default_title": "Looped In"
|
"default_title": "Looped In"
|
||||||
},
|
},
|
||||||
"content_security_policy": "script-src 'self'; object-src 'self'; connect-src 'self' https://hn.algolia.com"
|
"content_security_policy": "script-src 'self'; object-src 'self'; connect-src 'self' https://hn.algolia.com",
|
||||||
|
"web_accessible_resources": ["*.map"]
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
[org.clojure/clojurescript "1.9.946"]
|
[org.clojure/clojurescript "1.9.946"]
|
||||||
[org.clojure/core.async "0.3.465"]
|
[org.clojure/core.async "0.3.465"]
|
||||||
[cljs-ajax "0.7.3"]]
|
[cljs-ajax "0.7.3"]]
|
||||||
:source-paths ["src/build"]
|
:source-paths ["src_clj"]
|
||||||
:main looped-in.build
|
:main looped-in.build
|
||||||
:aliases {"build" ["run"]})
|
:aliases {"build" ["run"]})
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
(ns looped-in.build
|
|
||||||
(:require [cljs.build.api :as cljs]))
|
|
||||||
|
|
||||||
(defn build
|
|
||||||
[root opts]
|
|
||||||
(println (str "Compiling " root " to " (:output-to opts)))
|
|
||||||
(cljs/build root opts)
|
|
||||||
(println (str "Compiled " (:output-to opts))))
|
|
||||||
|
|
||||||
(defn -main [& args]
|
|
||||||
(build "src/content" {:output-to "ext/content.js"
|
|
||||||
:optimizations :simple
|
|
||||||
:closure-output-charset "US-ASCII"
|
|
||||||
:pretty-print true})
|
|
||||||
(build "src/background" {:output-to "ext/background.js"
|
|
||||||
:optimizations :simple
|
|
||||||
:closure-output-charset "US-ASCII"
|
|
||||||
:pretty-print true}))
|
|
12
src_clj/looped_in/build.clj
Normal file
12
src_clj/looped_in/build.clj
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
(ns looped-in.build
|
||||||
|
(:require [cljs.build.api :as cljs]))
|
||||||
|
|
||||||
|
(defn -main [& args]
|
||||||
|
(cljs/build "src_cljs" {:optimizations :simple
|
||||||
|
:source-map true
|
||||||
|
:pretty-print true
|
||||||
|
:output-dir "ext/out"
|
||||||
|
:modules {:content {:output-to "ext/content.js"
|
||||||
|
:entries #{"looped-in.content"}}
|
||||||
|
:background {:output-to "ext/background.js"
|
||||||
|
:entries #{"looped-in.background"}}}}))
|
@ -5,6 +5,12 @@
|
|||||||
|
|
||||||
(enable-console-print!)
|
(enable-console-print!)
|
||||||
|
|
||||||
|
(defn log [& args]
|
||||||
|
(apply js/console.log "[Looped In]" args))
|
||||||
|
|
||||||
|
(defn error [& args]
|
||||||
|
(apply js/console.error "[Looped In]" args))
|
||||||
|
|
||||||
(defn fetch-submission
|
(defn fetch-submission
|
||||||
"Fetches submissions from Hacker News by `url`"
|
"Fetches submissions from Hacker News by `url`"
|
||||||
[url]
|
[url]
|
||||||
@ -14,8 +20,8 @@
|
|||||||
"hitsPerPage" 1000
|
"hitsPerPage" 1000
|
||||||
"restrictSearchableAttributes" "url"}
|
"restrictSearchableAttributes" "url"}
|
||||||
:handler (fn [res] (go (>! response-chan res)))
|
:handler (fn [res] (go (>! response-chan res)))
|
||||||
:error-handler (fn [err] (js/console.error "Error fetching HN stories:"
|
:error-handler (fn [err] (error "Error fetching HN stories:"
|
||||||
(clj->js err)))})
|
(clj->js err)))})
|
||||||
response-chan))
|
response-chan))
|
||||||
|
|
||||||
(defn filter-response
|
(defn filter-response
|
||||||
@ -24,6 +30,7 @@
|
|||||||
;; request and this method for 5 minutes using localStorage
|
;; request and this method for 5 minutes using localStorage
|
||||||
[url response]
|
[url response]
|
||||||
(let [{:strs [hits]} response]
|
(let [{:strs [hits]} response]
|
||||||
|
(log "response" response)
|
||||||
(filter #(= (get % "url") url) hits)))
|
(filter #(= (get % "url") url) hits)))
|
||||||
|
|
||||||
(defn sort-hits
|
(defn sort-hits
|
||||||
@ -39,7 +46,7 @@
|
|||||||
(defn handle-hits
|
(defn handle-hits
|
||||||
"Handles a filtered response"
|
"Handles a filtered response"
|
||||||
[hits]
|
[hits]
|
||||||
(js/console.log (clj->js hits))
|
(log (clj->js hits))
|
||||||
(let [num-comments (total-num-comments hits)]
|
(let [num-comments (total-num-comments hits)]
|
||||||
(-> js/browser
|
(-> js/browser
|
||||||
(.-runtime)
|
(.-runtime)
|
Loading…
Reference in New Issue
Block a user