Skip to content

Commit

Permalink
Send transaction options to inspect (#28)
Browse files Browse the repository at this point in the history
* Use fulcro app id as the inspect app uuid

* Refactor to reduce warning

* Send tx options to inspect

* Increase send channel size to 50

* Add back `compressible-transact!`

* Make toggle! and set-value! mutations compressible

* Fix compressible-transact!
  • Loading branch information
wilkerlucio authored and awkay committed Jul 3, 2019
1 parent 63df0b7 commit 0c12448
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
15 changes: 15 additions & 0 deletions src/main/com/fulcrologic/fulcro/components.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@
you want to refresh on screen as an extra optimization. Idents are *not* checked against queries.
- `:abort-id` - An ID (you make up) that makes it possible (if the plugins you're using support it) to cancel
the network portion of the transaction (assuming it has not already completed).
- `:compressible?` - boolean. Check compressible-transact! docs.
NOTE: This function calls the application's `tx!` function (which is configurable). Fulcro 2 'follow-on reads' are
supported by the default version and are added to the `:refresh` entries. Your choice of rendering algorithm will
Expand Down Expand Up @@ -955,3 +956,17 @@
([component-or-app ref tx]
(transact! component-or-app tx {:optimistic? false
:ref ref})))

(defn compressible-transact!
"Identical to `transact!`, but marks the history edge as compressible. This means that if more than one
adjacent history transition edge is compressible, only the more recent of the sequence of them is kept. This
is useful for things like form input fields, where storing every keystoke in history is undesirable. This
also compress the transactions in Fulcro Inspect.
NOTE: history events that trigger remote interactions are not compressible, since they may be needed for
automatic network error recovery handling."
([comp-or-reconciler tx]
(transact! comp-or-reconciler tx {:compressible? true}))
([comp-or-reconciler ref tx]
(transact! comp-or-reconciler tx {:compressible? true
:ref ref})))
24 changes: 13 additions & 11 deletions src/main/com/fulcrologic/fulcro/inspect/inspect_client.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(defonce apps* (atom {}))
(def app-uuid-key :fulcro.inspect.core/app-uuid)

(defonce send-ch #?(:clj nil :cljs (async/chan (async/dropping-buffer 1024))))
(defonce send-ch #?(:clj nil :cljs (async/chan (async/dropping-buffer 50000))))
(defn post-message [type data]
#?(:cljs (async/put! send-ch [type data])))

Expand All @@ -38,6 +38,7 @@
(defn app-uuid [app] (some-> app :com.fulcrologic.fulcro.application/state-atom deref (get app-uuid-key)))
(defn remotes [app] (some-> (runtime-atom app) deref :com.fulcrologic.fulcro.application/remotes))
(defn app-id [app] (some-> (app-state app) :fulcro.inspect.core/app-id))
(defn fulcro-app-id [app] (:com.fulcrologic.fulcro.application/id app))
(defn get-component-name [component] (when component (some-> (util/isoget component :fulcro$options) :displayName)))
(defn comp-transact! [app tx options]
(let [tx! (ah/app-algorithm app :tx!)]
Expand Down Expand Up @@ -79,8 +80,6 @@
:fulcro.inspect.client/state-hash (hash new-state)
:fulcro.inspect.client/state-delta diff})))))



(defn event-data [event]
#?(:cljs (some-> event (gobj/getValueByKeys "data" "fulcro-inspect-devtool-message") encode/read)))

Expand Down Expand Up @@ -284,7 +283,7 @@
#?(:cljs
(let [networking (remotes app)
state* (state-atom app)
app-uuid (random-uuid)]
app-uuid (fulcro-app-id app)]
(swap! apps* assoc app-uuid app)
(update-state-history app @state*)
(swap! state* assoc app-uuid-key app-uuid)
Expand All @@ -300,15 +299,18 @@
app - The app
env - The mutation env that completed."
[app {:keys [component ref state] :as env} {:keys [tx-id tx component-name state-before]}]
[app
{:keys [component ref state com.fulcrologic.fulcro.algorithms.tx-processing/options]}
{:keys [tx-id tx state-before]}]
#?(:cljs
(let [component-name (get-component-name component)
tx (cond-> {:fulcro.inspect.ui.transactions/tx-id tx-id
:fulcro.history/client-time (js/Date.)
:fulcro.history/tx tx
:fulcro.history/db-before-hash (hash state-before)
:fulcro.history/db-after-hash (hash @state)
:fulcro.history/network-sends []}
tx (cond-> {:fulcro.inspect.ui.transactions/tx-id tx-id
:fulcro.history/client-time (js/Date.)
:fulcro.history/tx tx
:fulcro.history/db-before-hash (hash state-before)
:fulcro.history/db-after-hash (hash @state)
:fulcro.history/network-sends []
:com.fulcrologic.fulcro.algorithms.tx-processing/options options}
component-name (assoc :component component-name)
ref (assoc :ident-ref ref))
app-uuid (app-uuid app)]
Expand Down
4 changes: 2 additions & 2 deletions src/main/com/fulcrologic/fulcro/mutations.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@
"Toggle the given boolean `field` on the specified component. It is recommended you use this function only on
UI-related data (e.g. form checkbox checked status) and write clear top-level transactions for anything more complicated."
[comp field]
(comp/transact! comp `[(toggle {:field ~field})]))
(comp/transact! comp `[(toggle {:field ~field})] {:compressible? true}))

(defn set-value!
"Set a raw value on the given `field` of a `component`. It is recommended you use this function only on
UI-related data (e.g. form inputs that are used by the UI, and not persisted data). Changes made via these
helpers are compressed in the history."
[component field value]
(comp/transact! component `[(set-props ~{field value})]))
(comp/transact! component `[(set-props ~{field value})] {:compressible? true}))

#?(:cljs
(defn- ensure-integer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(ns com.fulcrologic.fulcro.algorithms.legacy-db-tree
(:refer-clojure :exclude [replace])
(:require
[clojure.zip :as zip]
[taoensso.timbre :as log]))
Expand Down Expand Up @@ -165,7 +164,7 @@
(recur (zip/right loc) path)))))))]
(query-template* (query-zip query) path)))

(defn- replace [template new-query]
(defn- zip-replace [template new-query]
(-> template (zip/replace new-query) zip/root))

(defn reduce-query-depth
Expand All @@ -175,7 +174,7 @@
(if-let [pos (query-template q [k])]
(let [node (zip/node pos)
node' (cond-> node (number? node) dec)]
(replace pos node'))
(zip-replace pos node'))
q)
q))

Expand Down

0 comments on commit 0c12448

Please sign in to comment.