mirror of
https://github.com/penpot/penpot.git
synced 2025-03-13 16:21:57 -05:00
Add webworkers architecture (rcp).
This commit is contained in:
parent
b920342188
commit
051163c3ae
3 changed files with 69 additions and 3 deletions
|
@ -7,7 +7,7 @@
|
|||
|
||||
(ra/start-figwheel!
|
||||
{:figwheel-options {:css-dirs ["resources/public/css"]}
|
||||
:build-ids ["dev"]
|
||||
:build-ids ["dev" "worker"]
|
||||
:all-builds
|
||||
[{:id "dev"
|
||||
:figwheel {:on-jsload "uxbox.ui/init"}
|
||||
|
@ -20,10 +20,24 @@
|
|||
"https://test.uxbox.io/api"}
|
||||
:warnings {:ns-var-clash false}
|
||||
:pretty-print true
|
||||
:language-in :ecmascript5
|
||||
:language-in :ecmascript6
|
||||
:language-out :ecmascript5
|
||||
:output-to "resources/public/js/main.js"
|
||||
:output-dir "resources/public/js"
|
||||
:verbose true}}
|
||||
|
||||
{:id "worker"
|
||||
:source-paths ["src" "vendor"]
|
||||
:compiler {:main 'uxbox.worker
|
||||
:asset-path "js"
|
||||
:parallel-build false
|
||||
:optimizations :simple
|
||||
:warnings {:ns-var-clash false}
|
||||
:pretty-print true
|
||||
:static-fns true
|
||||
:language-in :ecmascript6
|
||||
:language-out :ecmascript5
|
||||
:output-to "resources/public/js/worker.js"
|
||||
:verbose true}}]})
|
||||
|
||||
(ra/cljs-repl)
|
||||
(ra/cljs-repl "dev")
|
||||
|
|
21
src/uxbox/worker.cljs
Normal file
21
src/uxbox/worker.cljs
Normal file
|
@ -0,0 +1,21 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns uxbox.worker
|
||||
(:require [beicon.core :as rx]
|
||||
[uxbox.util.transit :as t]
|
||||
[uxbox.worker.core :as wrk]
|
||||
[uxbox.worker.align]))
|
||||
|
||||
(enable-console-print!)
|
||||
|
||||
(defn- on-message
|
||||
[event]
|
||||
(let [message (t/decode (.-data event))]
|
||||
(wrk/handler message)))
|
||||
|
||||
(defonce _
|
||||
(.addEventListener js/self "message" on-message))
|
31
src/uxbox/worker/core.cljs
Normal file
31
src/uxbox/worker/core.cljs
Normal file
|
@ -0,0 +1,31 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns uxbox.worker.core
|
||||
(:require [uxbox.util.transit :as t]))
|
||||
|
||||
(enable-console-print!)
|
||||
|
||||
;; --- Handler
|
||||
|
||||
(defmulti handler :cmd)
|
||||
|
||||
(defmethod handler :default
|
||||
[message]
|
||||
(println "Unexpected message:" message))
|
||||
|
||||
;; --- Helpers
|
||||
|
||||
(defn worker?
|
||||
"Check if the code is executed in webworker context."
|
||||
[]
|
||||
(undefined? (.-document js/self)))
|
||||
|
||||
(defn reply!
|
||||
[sender message]
|
||||
(let [message (assoc message :reply-to sender)]
|
||||
(println "replying " message)
|
||||
(.postMessage js/self (t/encode message))))
|
Loading…
Add table
Reference in a new issue