/
api.cljc
109 lines (94 loc) · 2.44 KB
/
api.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(ns portal.api
(:require #?(:clj
[portal.runtime.jvm.commands])
#?(:clj [portal.runtime.jvm.launcher :as l]
:cljs [portal.runtime.node.launcher :as l])
[clojure.set :as set]
[portal.runtime :as rt]))
(defn submit
"Tap target function.
Usage:
(add-tap #'portal.api/submit)
(remove-tap #'portal.api/submit)"
{:added "0.9.0"}
[value]
(rt/update-value value)
nil)
(defn tap
"Add portal as a tap> target."
{:added "0.1.0"
:deprecated "0.9"
:superseded-by "submit"}
[]
(add-tap #'submit)
nil)
(def ^:private long->short
{:portal.colors/theme :theme
:portal.launcher/app :app
:portal.launcher/host :host
:portal.launcher/port :port
:portal.launcher/window-title :window-title})
(defn- rename [options]
(set/rename-keys options long->short))
(defn set-defaults!
"Set default options for `open` and `start`.
Parameters passed directly to either will override defaults."
{:added "0.20.0"
:see-also ["open" "start"]}
[options]
(swap! rt/default-options merge (rename options)))
(defn start
"Start the HTTP server with non-default options. Only use if you need
control over the HTTP server."
{:added "0.6.2"}
[options]
(l/start (rename options)))
(defn open
"Open a new inspector window. A previous instance can be passed as
parameter to make sure it is open."
{:added "0.1.0"}
([] (open nil))
([portal-or-options]
(if (:session-id portal-or-options)
(open portal-or-options nil)
(open nil portal-or-options)))
([portal options]
(l/open portal (rename options))))
(defn close
"Close all current inspector windows."
{:added "0.1.0"}
([]
(l/close :all)
nil)
([portal]
(l/close portal)
nil))
(defn clear
"Clear all values."
{:added "0.1.0"}
([]
(l/clear :all)
nil)
([portal]
(l/clear portal)
nil))
(defn register!
"Register a var with portal. For now, the var should be a 1 arity fn.
Example: `(register! #'identity)`
The function name and doc string will show up in the command palette."
{:added "0.16.0"}
[var]
(rt/register! var)
nil)
(defn eval-str
"Evalute ClojureScript source given as a string in the UI runtime."
{:added "0.19.0"}
([source]
(l/eval-str :all source))
([portal source]
(l/eval-str portal source)))
(defn sessions
"Get all current portal sessions."
{:added "0.27.0"}
[]
(l/sessions))