aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/macros/example.js4
-rw-r--r--examples/macros/mystery-box.tsx15
2 files changed, 19 insertions, 0 deletions
diff --git a/examples/macros/example.js b/examples/macros/example.js
new file mode 100644
index 000000000..d612c1fa4
--- /dev/null
+++ b/examples/macros/example.js
@@ -0,0 +1,4 @@
+// source code
+import { mysteryBox } from "macro:./mystery-box";
+
+export default "You roll! " + mysteryBox(123);
diff --git a/examples/macros/mystery-box.tsx b/examples/macros/mystery-box.tsx
new file mode 100644
index 000000000..9e72ee1c0
--- /dev/null
+++ b/examples/macros/mystery-box.tsx
@@ -0,0 +1,15 @@
+// macro code:
+export function mysteryBox(node) {
+ const dice = Math.round(Math.random() * 100);
+ if (dice < 25) {
+ return <number value={5} />;
+ } else if (dice < 50) {
+ return <true />;
+ } else if (dice < 75) {
+ return <false />;
+ } else if (dice < 90) {
+ return <string value="a string" />;
+ } else {
+ return <string value={"a very rare string " + dice.toString(10)} />;
+ }
+}