Skip to content

Commit ec9a13b

Browse files
authored
Proper echo context handling (#183)
* Proper echo context handling * Update runtime structure * Update clear() to echo.clear() * Add observable notebook-kit attribution * Update test filename * Fix top-level async function * Update comments * Update comments * Resolve foo conflict to __foo__ * Normalize arraw function first * Fix arrow function rewrites * Fix example corpora-art-isms * Fix API reference * Handle echo as a param * Handle default params
1 parent b79fa89 commit ec9a13b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+596
-78
lines changed

LICENCE

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,23 @@ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1212
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
1313
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1414
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
15-
THIS SOFTWARE.
15+
THIS SOFTWARE.
16+
17+
---
18+
19+
Portions of this software are derived from Observable Notebook Kit, which is
20+
released under the ISC license.
21+
22+
Copyright 2025 Observable, Inc.
23+
24+
Permission to use, copy, modify, and/or distribute this software for any purpose
25+
with or without fee is hereby granted, provided that the above copyright notice
26+
and this permission notice appear in all copies.
27+
28+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
29+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
30+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
31+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
32+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
33+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
34+
THIS SOFTWARE.

app/docs/animations-authoring.recho.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ echo("~".repeat(x) + "(๑•̀ㅂ•́)و✧");
120120
const loop = () => {
121121
const x = 40 - (i++ % 40);
122122
const turtle = "🐢".padStart(x);
123-
clear(); // Clear the output of the current block.
123+
echo.clear(); // Clear the output of the current block.
124124
echo(turtle);
125125
};
126126

app/docs/api-reference.recho.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const array1000 = echo(recho.inspect(new Array(1000).fill(0), {limit: Infinity})
8383

8484
/**
8585
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86-
* clear()
86+
* echo.clear()
8787
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8888
*
8989
* Clear the output of the current block.
@@ -93,7 +93,7 @@ const array1000 = echo(recho.inspect(new Array(1000).fill(0), {limit: Infinity})
9393

9494
{
9595
echo("Hello, World!");
96-
setTimeout(() => clear(), 1000);
96+
setTimeout(() => echo.clear(), 1000);
9797
}
9898

9999
/**
@@ -113,7 +113,7 @@ const array1000 = echo(recho.inspect(new Array(1000).fill(0), {limit: Infinity})
113113
const timer = setInterval(() => {
114114
if (count-- <= 0) clearInterval(timer);
115115
else {
116-
clear();
116+
echo.clear();
117117
echo(count);
118118
}
119119
}, 1000);

app/docs/inline-echoing.recho.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,13 @@ const array1000 = echo(recho.inspect(new Array(1000).fill(0), {limit: 80}));
229229
* Clearing Output
230230
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
231231
*
232-
* You can call `clear` to clear the output of the current block. For example,
233-
* click the 🔁 button to see the output being cleared after 1 second.
232+
* You can call `echo.clear()` to clear the output of the current block. For
233+
* example, click the ▶️ button to see the output being cleared after 1 second.
234234
*/
235235

236236
{
237237
echo("hello world");
238-
setTimeout(() => clear(), 1000);
238+
setTimeout(() => echo.clear(), 1000);
239239
}
240240

241241
/**

app/docs/reactive-blocks.recho.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const random = echo(Math.random());
123123
const timer = setInterval(() => {
124124
if (count-- <= 0) clearInterval(timer);
125125
else {
126-
clear();
126+
echo.clear();
127127
echo(count);
128128
}
129129
}, 1000);

app/examples/corpora-art-isms.recho.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ const response = await fetch("https://raw.githubusercontent.com/dariusk/corpora/
2727
//➜ description: "A list of modernist art isms.",
2828
//➜ isms: [ "abstract expressionism", "academic", "action painting", "aestheticism", "art deco", "art nouveau", "avant-garde", "barbizon school", "baroque", "bauhaus", "biedermeier", "caravaggisti", "carolingian", "classicism", "cloisonnism", "cobra", "color field painting", "conceptual art", "cubism", "cubo-futurism", "dada", "dadaism", "de stijl", "deformalism", "der blaue reiter", "die brücke", "divisionism", "eclecticism", "ego-futurism", "existentialism", "expressionism", "fauvism", "fluxus", "formalism", "futurism", "geometric abstraction", "gothic art", "gründerzeit", "hard-edge painting", "historicism", "hudson river school", "humanism", "hyperrealism", "idealism", "illusionism", "immagine&poesia", "impressionism", "incoherents", "installation art", "international gothic", "intervention art", "jugendstil", "kinetic art", "land art", "les nabis", "lettrism", "lowbrow", "luminism", "lyrical abstraction", "mail art", "manierism", "mannerism", "maximalism", "merovingian", "metaphysical art ", "minimalism", "modern art", "modernism", "monumentalism", "multiculturalism", "naturalism", "neo-classicism", "neo-dada", "neo-expressionism", "neo-fauvism", "neo-geo", "neo-impressionism", "neo-minimalism", "neoclassicism", "neoism", "neue slowenische kunst", "new media art", "new objectivity", "nonconformism", "nouveau realisme", "op art", "orphism", "ottonian", "outsider art", "performance art", "perspectivism", "photorealism", "pointilism", "pop art", "post-conceptualism", "post-impressionism", "post-minimalism", "post-painterly abstraction", "post-structuralism", "postminimalism", "postmodern art", "postmodernism", "pre-raphaelites", "precisionism", "primitivism", "purism", "rayonism", "realism", "relational art", "remodernism", "renaissance", "rococo", "romanesque", "romanticism", "russian futurism", "russian symbolism", "scuola romana", "secularism", "situationist international", "social realism", "socialist realism", "sound art", "street art", "structuralism", "stuckism international", "stuckism", "superflat", "superstroke", "suprematism", "surrealism", "symbolism", "synchromism", "synthetism", "systems art", "tachism", "tachisme", "tonalism", "video art", "video game art", "vorticism", "young british artists" ]
2929
//➜ }
30-
const data = echo(await response.json(), {indent: 2, limit: Infinity});
30+
const data = await response.json();
31+
32+
echo(recho.inspect(data, {indent: 2, limit: Infinity}));
3133

3234
//➜ "academic"
3335
echo(data.isms[frame % data.isms.length]);

app/examples/ml5-handpose.recho.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ handPose.detectStart(video, (hands) => {
8484
for (let j = 0; j < width; ++j) output += buffer[i * width + j];
8585
output += i === height - 1 ? "" : "\n";
8686
}
87-
clear();
87+
echo.clear();
8888
echo(output);
8989
});
9090

editor/completion.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const builtinFunctions = [
2727
type: "function",
2828
detail: "()",
2929
info: "Clears the output of the current block.",
30-
apply: toApplyCompletion("clear()"),
30+
apply: toApplyCompletion("echo.clear()"),
3131
},
3232
{
3333
label: "invalidation",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"@observablehq/runtime": "^6.0.0",
7070
"@uiw/codemirror-theme-github": "^4.25.2",
7171
"acorn": "^8.15.0",
72+
"acorn-walk": "^8.3.4",
7273
"cheerio": "^1.1.2",
7374
"codemirror": "^6.0.2",
7475
"d3-array": "^3.2.4",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)