Skip to content

Commit

Permalink
switch to cljs-oops
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed Sep 20, 2016
1 parent 7003aa8 commit f7e1403
Show file tree
Hide file tree
Showing 58 changed files with 122 additions and 128 deletions.
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
[org.clojure/tools.logging "0.3.1"]
[org.clojure/tools.cli "0.3.5"]
[org.clojure/tools.nrepl "0.2.12"]
[binaryage/oops "0.2.0"]
[http-kit "2.2.0"]
[clj-logging-config "1.9.12"]
[version-clj "0.1.2"]
Expand All @@ -22,7 +23,7 @@

; we cannot use :dependencies under individual profiles because Cursive recognizes only root level
; thus we mark extra deps with :scope "test" and filter them later when producing jar library
[binaryage/chromex "0.4.2" :scope "test"]
[binaryage/chromex "0.5.0" :scope "test"]
[binaryage/devtools "0.8.2" :scope "test"]
[cljs-http "0.1.41" :scope "test"]
[figwheel "0.5.7" :scope "test"]
Expand Down
2 changes: 1 addition & 1 deletion src/automation/dirac/automation.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :refer [put! <! chan timeout alts! close!]]
[chromex.support :refer-macros [oget oset ocall oapply]]
[oops.core :refer [oget oset! ocall oapply]]
[chromex.logging :refer-macros [log error]]
[dirac.automation.machinery :as machinery]
[dirac.automation.helpers :as helpers]
Expand Down
2 changes: 1 addition & 1 deletion src/automation/dirac/automation/devtools.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns dirac.automation.devtools
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :refer [put! <! chan timeout alts! close!]]
[chromex.support :refer-macros [oget oset ocall oapply]]
[oops.core :refer [oget oset! ocall oapply]]
[chromex.logging :refer-macros [log warn error info]]
[devtools.core :as devtools]
[devtools.prefs :as devtools-prefs]))
Expand Down
8 changes: 4 additions & 4 deletions src/automation/dirac/automation/feedback.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns dirac.automation.feedback
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :refer [put! <! chan timeout alts! close!]]
[chromex.support :refer-macros [oget oset ocall oapply]]
[oops.core :refer [oget oset! ocall oapply]]
[chromex.logging :refer-macros [log warn]]
[dirac.automation.messages :as messages]
[dirac.automation.transcript-host :as transcript-host]))
Expand Down Expand Up @@ -30,11 +30,11 @@
; -- message processing -----------------------------------------------------------------------------------------------------

(defn process-event! [event]
(if-let [data (oget event "data")]
(case (oget data "type")
(if-let [data (oget event "?data")]
(case (oget data "?type")
"feedback-from-devtools" (append-to-transcript! "devtools" (oget data "transcript") (oget data "devtools"))
"feedback-from-extension" (append-to-transcript! "extension" (oget data "transcript"))
"feedback-from-scenario" (append-to-transcript! (or (oget data "label") "scenario") (oget data "transcript"))
"feedback-from-scenario" (append-to-transcript! (or (oget data "?label") "scenario") (oget data "transcript"))
nil)))

(defn start-processing-messages! []
Expand Down
2 changes: 1 addition & 1 deletion src/automation/dirac/automation/helpers.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns dirac.automation.helpers
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :refer [put! <! chan timeout alts! close!]]
[chromex.support :refer-macros [oget oset ocall oapply]]
[oops.core :refer [oget oset! ocall oapply]]
[cuerdas.core :as cuerdas])
(:import goog.Uri))

Expand Down
12 changes: 6 additions & 6 deletions src/automation/dirac/automation/launcher.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :refer [put! <! chan timeout alts! close!]]
[goog.string :as string]
[chromex.support :refer-macros [oget oset ocall oapply]]
[oops.core :refer [oget oset! oset!+ ocall ocall+ oapply]]
[chromex.logging :refer-macros [log warn error info]]
[dirac.settings :refer-macros [get-launch-task-key get-launch-task-message]]))

(defn register-task! [task-fn]
(oset js/window [(get-launch-task-key)] task-fn))
(oset!+ js/window (str "!" (get-launch-task-key)) task-fn))

(defn launch-task! []
(log "launching task...")
(ocall js/window (get-launch-task-key))) ; see go-task
(ocall+ js/window (get-launch-task-key))) ; see go-task

(defn launch-task-after-delay! [delay-ms]
(log "scheduled task launch after " delay-ms "ms...")
Expand All @@ -21,9 +21,9 @@
(launch-task!)))

(defn process-event! [event]
(if-let [data (oget event "data")]
(if (= (oget data "type") (get-launch-task-message))
(launch-task-after-delay! (string/parseInt (oget data "delay"))))))
(if-let [data (oget event "?data")]
(if (= (oget data "?type") (get-launch-task-message))
(launch-task-after-delay! (string/parseInt (oget data "?delay"))))))

(defn init! []
(.addEventListener js/window "message" process-event!))
2 changes: 1 addition & 1 deletion src/automation/dirac/automation/machinery.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns dirac.automation.machinery
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :refer [put! <! chan timeout alts! close!]]
[chromex.support :refer-macros [oget oset ocall oapply]]
[oops.core :refer [oget oset! ocall oapply]]
[chromex.logging :refer-macros [log error]]
[dirac.automation.task :as task]
[dirac.automation.transcript-host :as transcript]
Expand Down
8 changes: 4 additions & 4 deletions src/automation/dirac/automation/messages.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(:require [cljs.core.async :refer [put! <! chan timeout alts! close!]]
[cljs.reader :as reader]
[clojure.string :as str]
[chromex.support :refer-macros [oget oset ocall oapply]]
[oops.core :refer [oget oset! ocall oapply]]
[chromex.logging :refer-macros [log info warn error]]
[dirac.settings :refer-macros [get-marion-message-reply-timeout]]
[dirac.utils :as utils]))
Expand Down Expand Up @@ -98,7 +98,7 @@
; see https://developer.chrome.com/extensions/content_scripts#host-page-communication
(defn post-message-with-timeout! [js-message reply-timeout]
(let [message-id (get-next-message-id!)]
(oset js-message ["id"] message-id)
(oset! js-message "!id" message-id)
(let [post-message! #(.postMessage js/window js-message "*")]
(if (or (nil? reply-timeout) (= :no-timeout reply-timeout))
(go
Expand Down Expand Up @@ -176,8 +176,8 @@
; -- message processing -----------------------------------------------------------------------------------------------------

(defn process-event! [event]
(if-let [data (oget event "data")]
(case (oget data "type")
(if-let [data (oget event "?data")]
(case (oget data "?type")
"reply" (process-reply! data)
nil)))

Expand Down
2 changes: 1 addition & 1 deletion src/automation/dirac/automation/notifications.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns dirac.automation.notifications
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :refer [put! <! chan timeout alts! close!]]
[chromex.support :refer-macros [oget oset ocall oapply]]
[oops.core :refer [oget oset! ocall oapply]]
[chromex.logging :refer-macros [log warn]]
[dirac.automation.messages :as messages]
[cljs.reader :as reader]))
Expand Down
6 changes: 3 additions & 3 deletions src/automation/dirac/automation/runner.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns dirac.automation.runner
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :refer [put! <! chan timeout alts! close!]]
[chromex.support :refer-macros [oget oset ocall oapply]]
[oops.core :refer [oget oset! ocall oapply]]
[chromex.logging :refer-macros [log warn error info]]
[devtools.preload]
[dirac.automation.helpers :as helpers]
Expand All @@ -16,10 +16,10 @@
(helpers/get-el-by-id "resume-button"))

(defn enable-resume! []
(oset (get-resume-button-el) ["disabled"] false))
(oset! (get-resume-button-el) "disabled" false))

(defn disable-resume! []
(oset (get-resume-button-el) ["disabled"] true))
(oset! (get-resume-button-el) "disabled" true))

(defn wait-for-resume! []
(go
Expand Down
7 changes: 3 additions & 4 deletions src/automation/dirac/automation/runtime.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns dirac.automation.runtime
(:require-macros [chromex.support :refer [oget oset ocall oapply]])
(:require [chromex.logging :refer-macros [log warn error info]]
[chromex.support :refer-macros [oset oget]]
[oops.core :refer [oset! oget ocall oapply]]
[dirac.runtime :as runtime]
[dirac.runtime.prefs :as runtime-prefs]
[dirac.automation.helpers :as helpers]
Expand All @@ -18,10 +17,10 @@
(runtime-prefs/merge-prefs! prefs))))

(defn monkey-patch-runtime-get-version! [mock-version]
(oset js/window ["dirac" "runtime" "get_version"] (constantly mock-version)))
(oset! js/window ["dirac" "runtime" "get_version"] (constantly mock-version)))

(defn monkey-patch-runtime-repl-get-api-version! [mock-version]
(oset js/window ["dirac" "runtime" "repl" "get_api_version"] (constantly mock-version)))
(oset! js/window ["dirac" "runtime" "repl" "get_api_version"] (constantly mock-version)))

(defn promise-based-set-immediate [callback]
(-> (ocall js/Promise "resolve")
Expand Down
20 changes: 10 additions & 10 deletions src/automation/dirac/automation/scenario.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns dirac.automation.scenario
(:require [chromex.support :refer-macros [oget oset ocall oapply]]
(:require [oops.core :refer [oget oset! ocall oapply]]
[chromex.logging :refer-macros [log info warn error]]
[cljs.pprint :refer [pprint]]
[dirac.utils]
Expand Down Expand Up @@ -46,7 +46,7 @@
false)

(defn register-global-exception-handler! []
(oset js/window ["onerror"] scenario-exception-handler!))
(oset! js/window "onerror" scenario-exception-handler!))

; -- notification handler ---------------------------------------------------------------------------------------------------

Expand All @@ -73,10 +73,10 @@
(.apply orig js/console (to-array args))))

(defn store-console-api []
{"log" (oget js/window "console" "log")
"warn" (oget js/window "console" "warn")
"info" (oget js/window "console" "info")
"error" (oget js/window "console" "error")})
{"log" (oget js/window "console.log")
"warn" (oget js/window "console.warn")
"info" (oget js/window "console.info")
"error" (oget js/window "console.error")})

(defn captured-console-api [original-api]
{"log" (partial console-handler (get original-api "log") "LOG: ")
Expand All @@ -85,10 +85,10 @@
"error" (partial console-handler (get original-api "error") "ERROR: ")})

(defn set-console-api! [api]
(oset js/window ["console" "log"] (get api "log"))
(oset js/window ["console" "warn"] (get api "warn"))
(oset js/window ["console" "info"] (get api "info"))
(oset js/window ["console" "error"] (get api "error")))
(oset! js/window "console.log" (get api "log"))
(oset! js/window "console.warn" (get api "warn"))
(oset! js/window "console.info" (get api "info"))
(oset! js/window "console.error" (get api "error")))

(defn capture-console-as-feedback! []
{:pre [(nil? @original-console-api)]}
Expand Down
2 changes: 1 addition & 1 deletion src/automation/dirac/automation/status_host.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns dirac.automation.status-host
(:require [chromex.support :refer-macros [oget oset ocall oapply]]
(:require [oops.core :refer [oget oset! ocall oapply]]
[chromex.logging :refer-macros [log warn error info]]
[dirac.automation.helpers :as helpers]
[dirac.automation.status :as status]))
Expand Down
4 changes: 2 additions & 2 deletions src/automation/dirac/automation/task.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns dirac.automation.task
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :refer [put! <! chan timeout alts! close!]]
[chromex.support :refer-macros [oget oset ocall oapply]]
[oops.core :refer [oget oset! ocall oapply]]
[chromex.logging :refer-macros [log warn error info]]
[dirac.settings :refer-macros [get-signal-server-url
get-chrome-remote-debugging-port
Expand Down Expand Up @@ -208,4 +208,4 @@
false)

(defn register-global-exception-handler! []
(oset js/window ["onerror"] task-exception-handler!))
(oset! js/window "onerror" task-exception-handler!))
4 changes: 2 additions & 2 deletions src/automation/dirac/automation/transcript.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns dirac.automation.transcript
(:require [chromex.support :refer-macros [oget oset ocall oapply]]))
(:require [oops.core :refer [oget oset! ocall oapply]]))

; transcript is a <pre> tag which collects textual messages about test execution:
; 1) issued automation commands
Expand Down Expand Up @@ -35,7 +35,7 @@
(let [row-el (.createElement js/document "div")]
(if (some? style)
(.setAttribute row-el "style" style))
(oset row-el ["textContent"] text)
(oset! row-el "textContent" text)
(.appendChild transcript-el row-el)))

(defn read-transcript [transcript-el]
Expand Down
2 changes: 1 addition & 1 deletion src/automation/dirac/automation/transcript_host.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
get-transcript-label-padding-type]])
(:require [cljs.core.async :refer [put! <! chan timeout alts! close!]]
[dirac.automation.transcript :as transcript]
[chromex.support :refer-macros [oget oset ocall oapply]]
[oops.core :refer [oget oset! ocall oapply]]
[chromex.logging :refer-macros [log warn error info]]
[cuerdas.core :as cuerdas]
[dirac.automation.helpers :as helpers]
Expand Down
2 changes: 1 addition & 1 deletion src/automation/dirac/automation/verbs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Low-level automation API"
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :refer [put! <! chan timeout alts! close!]]
[chromex.support :refer-macros [oget oset ocall oapply]]
[oops.core :refer [oget oset! ocall oapply]]
[chromex.logging :refer-macros [log error]]
[dirac.automation.transcript-host :as transcript]
[dirac.automation.matchers :as matchers]
Expand Down
2 changes: 1 addition & 1 deletion src/background/dirac/background/chrome.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require-macros [cljs.core.async.macros :refer [go go-loop]]
[dirac.background.logging :refer [log info warn error]])
(:require [cljs.core.async :refer [<! chan put!]]
[chromex.support :refer-macros [oget ocall oapply oset]]
[oops.core :refer [oget ocall oapply oset!]]
[chromex.chrome-event-channel :refer [make-chrome-event-channel]]
[chromex.protocols :refer [post-message! get-sender get-name]]
[chromex.ext.runtime :as runtime]
Expand Down
2 changes: 1 addition & 1 deletion src/background/dirac/background/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require-macros [cljs.core.async.macros :refer [go go-loop]]
[dirac.background.logging :refer [log info warn error]])
(:require [cljs.core.async :refer [<! chan put!]]
[chromex.support :refer-macros [oget ocall oapply]]
[oops.core :refer [oget ocall oapply]]
[chromex.chrome-event-channel :refer [make-chrome-event-channel]]
[chromex.protocols :refer [post-message! get-sender get-name]]
[dirac.background.chrome :as chrome]
Expand Down
2 changes: 1 addition & 1 deletion src/background/dirac/background/devtools.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns dirac.background.devtools
(:require [chromex.support :refer-macros [oget ocall oapply]]
(:require [oops.core :refer [oget ocall oapply]]
[chromex.logging :refer-macros [log info warn error group group-end]]
[dirac.background.action :as action]
[dirac.background.marion :as marion]
Expand Down
10 changes: 5 additions & 5 deletions src/background/dirac/background/helpers.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns dirac.background.helpers
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :refer [<! chan put! close! timeout]]
[chromex.support :refer-macros [oget oset ocall oapply]]
[oops.core :refer [oget oget+ oset! oset!+ ocall oapply]]
[chromex.logging :refer-macros [log info warn error group group-end]]
[chromex.ext.tabs :as tabs]
[chromex.ext.extension :as extension]
Expand Down Expand Up @@ -105,11 +105,11 @@
(filter (partial is-devtools-view? devtools-id) (extension/get-views)))

(defn has-automation-support? [view]
(some? (oget view (get-automation-entry-point-key))))
(some? (oget+ view (str "?" (get-automation-entry-point-key)))))

(defn get-automation-entry-point [view]
{:post [(fn? %)]}
(oget view (get-automation-entry-point-key)))
(oget+ view (get-automation-entry-point-key)))

(defn safe-serialize [value]
(try
Expand Down Expand Up @@ -177,7 +177,7 @@
(let [matching-views (get-devtools-views devtools-id)]
(if (= (count matching-views) 1)
(let [view (first matching-views)]
(oset view [(get-dirac-intercom-key)] handler)
(when-let [flush-fn (oget view (get-flush-pending-feedback-messages-key))]
(oset!+ view (str "!" (get-dirac-intercom-key)) handler)
(when-let [flush-fn (oget+ view (str "?" (get-flush-pending-feedback-messages-key)))]
(flush-fn)))
(error "unable to install intercom from dirac extension to dirac frontend" devtools-id))))
2 changes: 1 addition & 1 deletion src/background/dirac/background/marion.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require-macros [cljs.core.async.macros :refer [go go-loop]]
[dirac.background.logging :refer [log info warn error]])
(:require [cljs.core.async :refer [<! chan put!]]
[chromex.support :refer-macros [oget ocall oapply]]
[oops.core :refer [oget ocall oapply]]
[chromex.protocols :refer [post-message! get-sender get-name]]
[devtools.toolbox :refer [envelope]]
[dirac.background.state :as state]
Expand Down
2 changes: 1 addition & 1 deletion src/background/dirac/background/state.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns dirac.background.state
(:require-macros [dirac.background.logging :refer [log info warn error]])
(:require [chromex.support :refer-macros [oget oset ocall oapply]]
(:require [oops.core :refer [oget oset! ocall oapply]]
[chromex.protocols :refer [post-message! get-sender get-name]]
[devtools.toolbox :as toolbox]
[dirac.utils :as utils]
Expand Down
2 changes: 1 addition & 1 deletion src/background/dirac/background/thief.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require-macros [cljs.core.async.macros :refer [go go-loop]]
[dirac.background.logging :refer [log info warn error]])
(:require [cljs.core.async :refer [<! chan timeout]]
[chromex.support :refer-macros [oget oset ocall oapply]]
[oops.core :refer [oget oset! ocall oapply]]
[chromex.ext.page-capture :as page-capture]
[dirac.mime :as mime]
[dirac.quoted-printable :as qp]
Expand Down
2 changes: 1 addition & 1 deletion src/background/dirac/background/tools.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns dirac.background.tools
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :refer [<! chan timeout close! put!]]
[chromex.support :refer-macros [oget oset ocall oapply]]
[oops.core :refer [oget oset! ocall oapply]]
[chromex.logging :refer-macros [log info warn error group group-end]]
[chromex.ext.windows :as windows]
[chromex.ext.tabs :as tabs]
Expand Down
Loading

0 comments on commit f7e1403

Please sign in to comment.