|
23 | 23 | ;; Navigating Inspector State
|
24 | 24 | ;;
|
25 | 25 |
|
26 |
| -(declare inspect-render) |
| 26 | +(declare inspect-render supported-view-modes) |
27 | 27 |
|
28 | 28 | (defn push-item-to-path
|
29 | 29 | "Takes `path` and the role and key of the value to be navigated to, and returns
|
|
177 | 177 | ;; :current-page may be wrong, recompute it.
|
178 | 178 | current-page (if (number? child-key)
|
179 | 179 | (quot child-key page-size)
|
180 |
| - current-page)] |
181 |
| - (-> inspector |
182 |
| - (assoc :value child) |
183 |
| - (dissoc :value-analysis) |
184 |
| - (update :stack conj value) |
185 |
| - (assoc :current-page 0) |
186 |
| - (update :pages-stack conj current-page) |
187 |
| - (assoc :view-mode :normal) |
188 |
| - (update :view-modes-stack conj view-mode) |
189 |
| - (update :path push-item-to-path child-role child-key)))) |
| 180 | + current-page) |
| 181 | + ins (-> inspector |
| 182 | + (assoc :value child) |
| 183 | + (dissoc :value-analysis) |
| 184 | + (update :stack conj value) |
| 185 | + (assoc :current-page 0) |
| 186 | + (update :pages-stack conj current-page) |
| 187 | + (update :view-modes-stack conj view-mode) |
| 188 | + (update :path push-item-to-path child-role child-key))] |
| 189 | + (assoc ins :view-mode (first (supported-view-modes ins))))) |
190 | 190 |
|
191 | 191 | (defn down
|
192 | 192 | "Drill down to an indexed object referred to by the previously rendered value."
|
|
290 | 290 |
|
291 | 291 | ;; View modes
|
292 | 292 |
|
293 |
| -(def ^:private view-mode-order [:normal :hex :table :object]) |
| 293 | +(def ^:private view-mode-order [:hex :normal :table :object]) |
294 | 294 |
|
295 | 295 | (defmulti view-mode-supported? (fn [_inspector view-mode] view-mode))
|
296 | 296 |
|
|
318 | 318 | (pre-ex (view-mode-supported? inspector mode))
|
319 | 319 | (inspect-render (assoc inspector :view-mode mode)))
|
320 | 320 |
|
| 321 | +(defn- supported-view-modes [inspector] |
| 322 | + (filter #(view-mode-supported? inspector %) view-mode-order)) |
| 323 | + |
321 | 324 | (defn toggle-view-mode
|
322 | 325 | "Switch to the next supported view mode."
|
323 | 326 | [{:keys [view-mode] :as inspector}]
|
324 |
| - (let [supported (filter #(view-mode-supported? inspector %) view-mode-order) |
| 327 | + (let [supported (supported-view-modes inspector) |
325 | 328 | transitions (zipmap supported (rest (cycle supported)))]
|
326 | 329 | (set-view-mode inspector (transitions view-mode))))
|
327 | 330 |
|
|
1116 | 1119 | of supported keys."
|
1117 | 1120 | ([value] (start {} value))
|
1118 | 1121 | ([config value]
|
1119 |
| - (-> default-inspector-config |
1120 |
| - (merge (validate-config config)) |
1121 |
| - (assoc :stack [], :path [], :pages-stack [], :current-page 0, |
1122 |
| - :view-modes-stack [], :view-mode :normal, :value value) |
1123 |
| - (inspect-render)))) |
| 1122 | + (let [inspector (-> default-inspector-config |
| 1123 | + (merge (validate-config config)) |
| 1124 | + (assoc :stack [], :path [], :pages-stack [], :current-page 0, |
| 1125 | + :view-modes-stack [], :value value))] |
| 1126 | + (-> inspector |
| 1127 | + (assoc :view-mode (first (supported-view-modes inspector))) |
| 1128 | + inspect-render)))) |
1124 | 1129 |
|
1125 | 1130 | (defn ^:deprecated clear
|
1126 | 1131 | "If necessary, use `(start inspector nil) instead.`"
|
|
0 commit comments