enhance: pub-event! returns a promise (#9671)

enhance: pub-event! returns a promise

fix: typing 1.  sometimes can result in 1. 1.
pull/9661/head
Tienson Qin 2023-06-15 23:45:13 +08:00 committed by GitHub
parent eafca05387
commit 2d0f67429a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 16 deletions

View File

@ -1873,10 +1873,9 @@
(cond
(and (= content "1. ") (= last-input-char " ") input-id edit-block
(not (own-order-number-list? edit-block)))
(do
(state/set-edit-content! input-id "")
(-> (p/delay 10)
(p/then #(state/pub-event! [:editor/toggle-own-number-list edit-block]))))
(p/do!
(state/pub-event! [:editor/toggle-own-number-list edit-block])
(state/set-edit-content! input-id ""))
(and (= last-input-char commands/command-trigger)
(or (re-find #"(?m)^/" (str (.-value input))) (start-of-new-word? input pos)))

View File

@ -966,15 +966,20 @@
[]
(let [chan (state/get-events-chan)]
(async/go-loop []
(let [payload (async/<! chan)]
(try
(handle payload)
(catch :default error
(let [type :handle-system-events/failed]
(js/console.error (str type) (clj->js payload) "\n" error)
(state/pub-event! [:capture-error {:error error
:payload {:type type
:payload payload}}])))))
(let [[payload d] (async/<! chan)]
(->
(try
(p/resolved (handle payload))
(catch :default error
(p/rejected error)))
(p/then (fn [result]
(p/resolve! d result)))
(p/catch (fn [error]
(let [type :handle-system-events/failed]
(state/pub-event! [:capture-error {:error error
:payload {:type type
:payload payload}}])
(p/reject! d error))))))
(recur))
chan))

View File

@ -760,7 +760,7 @@ Similar to re-frame subscriptions"
(when-let [graphs (seq (get-in @state [:file-sync/remote-graphs :graphs]))]
(some #(when (= (:GraphUUID %) (str uuid)) %) graphs)))
(defn get-remote-graph-usage
(defn get-remote-graph-usage
[]
(when-let [graphs (seq (get-in @state [:file-sync/remote-graphs :graphs]))]
(->> graphs
@ -1721,8 +1721,10 @@ Similar to re-frame subscriptions"
(defn pub-event!
{:malli/schema [:=> [:cat vector?] :any]}
[payload]
(let [chan (get-events-chan)]
(async/put! chan payload)))
(let [d (p/deferred)
chan (get-events-chan)]
(async/put! chan [payload d])
d))
(defn get-export-block-text-indent-style []
(:copy/export-block-text-indent-style @state))