Skip to content

Commit 81812d8

Browse files
committed
add shared ns
1 parent af0fb5e commit 81812d8

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

src/electron/file.cljs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
["fs" :as fs]
55
["path" :as path]
66
[clojure.edn :as edn]
7-
[config :as config]))
7+
[config :as config]
8+
[shared :as shared]))
89

910
(def dialog-options
1011
{:defaultPath (.getPath app config/default-path)
@@ -20,7 +21,7 @@
2021

2122
(defn write-file!
2223
[file-path data]
23-
(let [document (pr-str (dissoc data :path :id :title))]
24+
(let [document (shared/document->save-format data)]
2425
(-> (.writeFile fs/promises file-path document "utf-8")
2526
(.then #(-> (select-keys data [:id])
2627
(serialize-document file-path))))))

src/renderer/document/events.cljs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
[renderer.utils.compatibility :as utils.compatibility]
2121
[renderer.utils.element :as utils.element]
2222
[renderer.utils.math :refer [Vec2]]
23-
[renderer.utils.vec :as utils.vec]))
23+
[renderer.utils.vec :as utils.vec]
24+
[shared :as shared]))
2425

2526
(def file-picker-options
2627
{:startIn config/default-path
@@ -232,7 +233,7 @@
232233
(let [document (document.handlers/persisted-format db)]
233234
(if (= (:platform db) "web")
234235
{::effects/file-save
235-
{:data (document.handlers/save-format document)
236+
{:data (shared/document->save-format document)
236237
:options file-picker-options
237238
:formatter (fn [file] {:id (:id document)
238239
:title (.-name file)})
@@ -249,7 +250,7 @@
249250
::download
250251
(fn [{:keys [db]} [_]]
251252
(let [document (document.handlers/persisted-format db)]
252-
{::effects/download {:data (document.handlers/save-format document)
253+
{::effects/download {:data (shared/document->save-format document)
253254
:title (str "document." config/ext)}})))
254255

255256
(rf/reg-event-fx
@@ -258,7 +259,7 @@
258259
(let [document (document.handlers/persisted-format db id)]
259260
(if (= (:platform db) "web")
260261
{::effects/file-save
261-
{:data (document.handlers/save-format document)
262+
{:data (shared/document->save-format document)
262263
:options file-picker-options
263264
:formatter (fn [file] {:id id
264265
:title (.-name file)})
@@ -277,7 +278,7 @@
277278
(let [document (document.handlers/persisted-format db)]
278279
(if (= (:platform db) "web")
279280
{::effects/file-save
280-
{:data (document.handlers/save-format document)
281+
{:data (shared/document->save-format document)
281282
:options file-picker-options
282283
:formatter (fn [file] {:id (:id document)
283284
:title (.-name file)})

src/renderer/document/handlers.cljs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@
5151
document
5252
m.transform/strip-extra-keys-transformer))))))
5353

54-
(m/=> save-format [:-> PersistedDocument string?])
55-
(defn save-format
56-
[document]
57-
(-> document
58-
(dissoc :path :id :title)
59-
(pr-str)))
60-
6154
(m/=> close [:-> App uuid? App])
6255
(defn close
6356
[db id]

src/shared.cljs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(ns shared
2+
(:require
3+
[malli.core :as m]
4+
[renderer.document.db :refer [PersistedDocument]]))
5+
6+
(m/=> document->save-format [:-> PersistedDocument string?])
7+
(defn document->save-format
8+
[document]
9+
(-> document
10+
(dissoc :path :id :title)
11+
(pr-str)))

0 commit comments

Comments
 (0)