-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnotebook-demo.js
210 lines (158 loc) · 9.28 KB
/
notebook-demo.js
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
const { demo, wait, group, immediate, using } = require("demokit");
const { paste, br, type, key } = require("demokit/keyboard");
const window = require("demokit/window");
const editor = require("demokit/window/code-editor");
const browser = require("demokit/window/browser");
const fs = require("fs");
const clean = require("./clean-runkit");
const { callout, blurb } = require("demokit/callout");
const { span, i, button } = require("demokit/html");
const mouse = require("demokit/mouse");
const dialog = require("./dialog");
const comment = require("./comment");
const styledBlurb = <blurb style = "font-family: 'Lato', 'Roboto'; color: #ccc;" />;
const wordmark = <span style = "font-family: 'Fira Sans'; font-weight: bold;" />;
module.exports = async function NotebookDemo()
{
return <demo>
<dialog.type id = "dialog"> is a node playground in your browser.</dialog.type>
<wait delay = { 1500 } />
<group animate = { true }>
<dialog.moveUp id = "dialog"/>
<window.style id = "notebook-browser" opacity = { 1 } y = { 150 } />
</group>
<immediate>
<dialog.showButton id = "dialog" which = "right"/>
</immediate>
<using window = "notebook-browser">
<selectCell index = { 1 } />
{/* Cell 1 */}
<wait delay = { 1000 } />
<comment newline = { false } >RunKit runs real node just like your REPL...</comment>
<type>"Node.js " + process.version</type>
<wait delay = { 500 } />
<mouse.click selector = "span[data-queriable-engines-drop-down=true]" />
<wait delay = { 500 } />
<mouse.click selector = "span[value='10.x.x']" />
<clickLastRunButton />
<wait delay = { 1000 } />
{/* Cell 2 */}
<comment>...except you can require ANY package from npm instantly:</comment>
<mouse.click selector = "button svg" />
<wait delay = { 500 } />
<wait.visible selector = ".module-search" />
<type>roman numeral</type>
<wait delay = { 1000 } />
<mouse.move selector = "button.require-button"/>
<mouse.effect selector = "button.require-button"/>
<wait delay = { 100 } />
<key code = "Escape"/>
<immediate>
<mouse.hide/>
</immediate>
<selectCell index = { 2 } />
<paste>require("roman-numeral")</paste>
<wait delay = { 500 } />
<type>.convert(2016)</type>
<clickLastRunButton/>
<wait delay = { 1000 } />
{/* Cell 3 */}
<comment>RunKit can also VISUALIZE your results.</comment>
<comment>Let's get the location of the International Space Station:</comment>
<type>
const getJSON = require(<wait delay = { 200 }/><paste>"async-get-json"</paste>);<br/>
const ISS_API = <wait delay = { 200 }/><paste>"http://api.open-notify.org/iss-now.json"</paste>;<wait delay = { 200 }/><br/>
(await getJSON(ISS_API)).iss_position;
</type>
<clickLastRunButton/>
<wait.visible selector = ".leaflet-container" />
<window.scroll selector = "span[value='com.tonicdev.coordinates-as-map']" />
<window.style dx = { 300 } animate = { true } />
<callout from = { { x: 670, y: 163 } } to = { { x: 750, y: 163 } }>
<styledBlurb>
<wordmark>RunKit</wordmark> shows results using special <i>object viewers</i>.
</styledBlurb>
<styledBlurb>
In this case <wordmark>RunKit</wordmark> chose a map viewer because the result <i>looked like</i> a geographic coordinate.
</styledBlurb>
<styledBlurb>
You can always show the native representation by choosing the <i>properties viewer</i> from the pop up menu.
</styledBlurb>
<mouse.click selector = { `${cellSelector(3)} span[value='com.tonicdev.coordinates-as-map']` } />
<mouse.click selector = { `${cellSelector(3)} .dropdown-menu span[value='com.tonic.properties-and-prototype-of']` } reveal = { true } />
</callout>
<window.style dx = { -300 } animate = { true } />
<wait delay = { 1000 } />
<mouse.click selector = { `${cellSelector(3)} span[value='com.tonicdev.coordinates-as-map']` } />
<mouse.click selector = { `${cellSelector(3)} .dropdown-menu span[value='com.tonicdev.coordinates-as-map']` } reveal = { true } />
<wait delay = { 1000 } />
<window.scroll selector = { cellSelector(4) } />
<selectCell index = { 4 } />
{/* Cell 4 */}
<comment>Let's require a RunKit playground to play with GitHub data:</comment>
<type>const stats = require("@runkit/runkit/github-stats/1.0.0");</type><br/>
<type>const R = require("ramda");</type><br/>
<br/>
<comment>We can now find the most popular repos on GitHub:</comment>
<type>const repos = (await stats.getMostPopularRepos({ limit: 3 }));</type><br/>
<type>const names = R.pluck("full_name", repos);</type>
<clickLastRunButton/>
<wait.visible selector = { `${cellSelector(4)} .object-description` } />
<window.scroll selector = { `${cellSelector(4)} .object-description` } />
<wait delay = { 1000 } />
<window.scroll selector = { cellSelector(5) } />
{/* Cell 5 */}
<comment>Cool! But let's see which is the most active.</comment>
<comment>Every cell still has access to the data before it:</comment>
<type>const { map } = require("bluebird");</type><br/>
<type>const commits = await map(names, stats.getCommitActivity);</type><br/>
<type>const commitsPerDay = R.pluck("days", commits);</type><br/>
<br/>
<type>R.zipObj(names, commitsPerDay);</type>
<clickLastRunButton/>
<wait.visible selector = { `${cellSelector(5)} .object-description` } />
<window.scroll selector = { `${cellSelector(5)} .object-description` } />
<wait delay = { 1000 } />
<window.style dx = { 300 } animate = { true } />
<callout from = { { x: 670, y: 163 } } to = { { x: 750, y: 163 } }>
<styledBlurb>
This just an ordinary JavaScript object, but we can again use the pop up menu
to choose a more interesting viewer.
</styledBlurb>
<mouse.click selector = { `${cellSelector(5)} span[value='com.tonic.properties-and-prototype-of']` } />
<mouse.click selector = { `${cellSelector(5)} span[value='com.tonic.chart-from-object-of-objects']` } reveal = { true } />
<wait.visible selector = { `${cellSelector(5)} .c3-event-rect` } />
<window.scroll selector = { `${cellSelector(5)} .object-description` } />
<styledBlurb>
<wordmark>RunKit</wordmark> was able to show us this data as a much easier to read <i>graph</i>
</styledBlurb>
</callout>
<window.style dx = { -300 } animate = { true } />
<wait delay = { 2000 }/>
</using>
<group animate = { true } >
<dialog.moveDown id = "dialog" />
<window.style id = "notebook-browser" opacity = { 0 } y = { 500 } />
</group>
</demo>
}
function clickLastRunButton({ window })
{
return <mouse.click window = { window } selector = "button.run-button" reveal = { true } />
}
async function selectCell({ window:aWindow, index })
{
return <using window = { aWindow } >
<mouse.click move = { false } effect = { false } selector = { `${cellSelector(index)} .source-editor` } />
<wait.visible selector = { `${cellSelector(index)}.focused` } />
<key code = "Down" />
</using>
}
function cellSelector(anIndex)
{
return ".cell-container:nth-of-type(" + (anIndex + 2) + ")";
}
module.exports.initialize = function initialize()
{
return <clean window = "notebook-browser" />
}