0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-26 08:29:42 -05:00

Move worker code into uxbox-worker namespace.

This commit is contained in:
Andrey Antukh 2016-06-12 13:38:18 +03:00
parent 0a17a44560
commit c13e86c735
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
6 changed files with 13 additions and 14 deletions

View file

@ -5,7 +5,7 @@
(let [start (System/nanoTime)] (let [start (System/nanoTime)]
(b/build (b/build
(b/inputs "src" "vendor") (b/inputs "src" "vendor")
{:main 'uxbox.worker {:main 'uxbox-worker.main
:output-to "resources/public/js/worker.js" :output-to "resources/public/js/worker.js"
:output-dir "resources/public/js/worker" :output-dir "resources/public/js/worker"
:asset-path "js" :asset-path "js"

View file

@ -26,7 +26,6 @@
:output-to "resources/public/js/main.js" :output-to "resources/public/js/main.js"
:output-dir "resources/public/js" :output-dir "resources/public/js"
:verbose true}} :verbose true}}
#_{:id "preview" #_{:id "preview"
;; :figwheel {:on-jsload "uxbox.ui/init"} ;; :figwheel {:on-jsload "uxbox.ui/init"}
:source-paths ["src" "vendor"] :source-paths ["src" "vendor"]

View file

@ -2,7 +2,7 @@
(b/watch (b/watch
(b/inputs "src" "vendor") (b/inputs "src" "vendor")
{:main 'uxbox.worker {:main 'uxbox-worker.main
:output-to "resources/public/js/worker.js" :output-to "resources/public/js/worker.js"
:output-dir "resources/public/js/worker" :output-dir "resources/public/js/worker"
:asset-path "js" :asset-path "js"

View file

@ -4,26 +4,26 @@
;; ;;
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz> ;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.worker.align (ns uxbox-worker.align
"Workspace aligment indexes worker." "Workspace aligment indexes worker."
(:require [beicon.core :as rx] (:require [beicon.core :as rx]
[kdtree.core :as kd] [kdtree.core :as kd]
[uxbox.worker.core :as wrk] [uxbox-worker.impl :as impl]
[uxbox.util.geom.point :as gpt])) [uxbox.util.geom.point :as gpt]))
(defonce tree (kd/create)) (defonce tree (kd/create))
(defmethod wrk/handler :grid/init (defmethod impl/handler :grid/init
[{:keys [sender width height x-axis y-axis] :as opts}] [{:keys [sender width height x-axis y-axis] :as opts}]
(time (time
(let [value (kd/generate width height (or x-axis 10) (or y-axis 10))] (let [value (kd/generate width height (or x-axis 10) (or y-axis 10))]
(set! tree value))) (set! tree value)))
(wrk/reply! sender nil)) (impl/reply! sender nil))
(defmethod wrk/handler :grid/align (defmethod impl/handler :grid/align
[{:keys [sender point] :as message}] [{:keys [sender point] :as message}]
(let [point #js [(:x point) (:y point)] (let [point #js [(:x point) (:y point)]
results (js->clj (kd/nearest tree point 1)) results (js->clj (kd/nearest tree point 1))
[[x y] d] (first results) [[x y] d] (first results)
result (gpt/point x y)] result (gpt/point x y)]
(wrk/reply! sender {:point (gpt/point x y)}))) (impl/reply! sender {:point (gpt/point x y)})))

View file

@ -4,7 +4,7 @@
;; ;;
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz> ;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.worker.core (ns uxbox-worker.impl
(:require [uxbox.util.transit :as t])) (:require [uxbox.util.transit :as t]))
(enable-console-print!) (enable-console-print!)

View file

@ -4,18 +4,18 @@
;; ;;
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz> ;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.worker (ns uxbox-worker.main
(:require [beicon.core :as rx] (:require [beicon.core :as rx]
[uxbox.util.transit :as t] [uxbox.util.transit :as t]
[uxbox.worker.core :as wrk] [uxbox-worker.impl :as impl]
[uxbox.worker.align])) [uxbox-worker.align]))
(enable-console-print!) (enable-console-print!)
(defn- on-message (defn- on-message
[event] [event]
(let [message (t/decode (.-data event))] (let [message (t/decode (.-data event))]
(wrk/handler message))) (impl/handler message)))
(defonce _ (defonce _
(.addEventListener js/self "message" on-message)) (.addEventListener js/self "message" on-message))