Skip to content

Commit 886fdcd

Browse files
authored
feat(marko): udpate examples for v6 (#299)
1 parent a45e56b commit 886fdcd

File tree

25 files changed

+101
-70
lines changed

25 files changed

+101
-70
lines changed

build/lib/playgroundUrlByFramework.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,17 @@ export default {
9292

9393
return generateURLFromData(data);
9494
},
95-
marko: (contentByFilename) => {
96-
const BASE_URL = "https://markojs.com/playground/#";
97-
95+
marko: async (contentByFilename) => {
96+
let firstFile = true;
9897
const data = Object.entries(contentByFilename).map(([path, content]) => ({
99-
name: nodePath.parse(path).base,
100-
path: `/components/${path}`,
98+
path: firstFile ? (firstFile = false) || "index.marko" : path,
10199
content,
102100
}));
103101

104-
return BASE_URL + compressToURL(JSON.stringify(data));
102+
return (
103+
"https://markojs.com/playground#" +
104+
(await markoCompress(JSON.stringify(data)))
105+
);
105106
},
106107
};
107108

@@ -158,3 +159,30 @@ async function compress_and_encode_text(input) {
158159
}
159160
}
160161
}
162+
163+
// method `compress` from https://github.com/marko-js/website/blob/main/src/util/hasher.ts#L8-L25
164+
export async function markoCompress(value) {
165+
const stream = new CompressionStream("gzip");
166+
const writer = stream.writable.getWriter();
167+
writer.write(new TextEncoder().encode(value));
168+
writer.close();
169+
170+
let result = "v2";
171+
const reader = stream.readable.getReader();
172+
try {
173+
while (true) {
174+
const { value, done } = await reader.read();
175+
if (done) break;
176+
for (const byte of value) {
177+
result += String.fromCharCode(byte);
178+
}
179+
}
180+
181+
return btoa(result)
182+
.replace(/=+$/, "")
183+
.replace(/\+/g, "-")
184+
.replace(/\//g, "_");
185+
} finally {
186+
reader.releaseLock();
187+
}
188+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<let/name = "John"/>
1+
<let/name="John">
22
<h1>Hello ${name}</h1>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<let/name = "John"/>
2-
<effect() { name = "Jane" }/>
1+
<let/name="John">
2+
<script>name = "Jane"</script>
33
<h1>Hello ${name}</h1>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<let/count = 10/>
2-
<const/doubleCount = count * 2/>
1+
<let/count=10>
2+
<const/doubleCount=count * 2>
33
<div>${doubleCount}</div>

content/2-templating/2-styling/marko/CssStyle.marko

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h1.title>I am red</h1>
2-
<button style={ fontSize: "10rem" }>I am a button</button>
2+
<button style={ "font-size": "10rem" }>I am a button</button>
33
<button class=scopedButton>I am a style-scoped button</button>
44

55
<style>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<let/count = 0/>
1+
<let/count=0>
22
<p>Counter: ${count}</p>
33
<button onClick() { count++ }>+1</button>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
<input/inputElement>
2-
<effect() { inputElement().focus() }/>
2+
<script>
3+
inputElement().focus();
4+
</script>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
static const TRAFFIC_LIGHTS = ["red", "orange", "green"];
2-
<let/lightIndex = 0/>
3-
<const/light = TRAFFIC_LIGHTS[lightIndex]/>
2+
<let/lightIndex=0>
3+
<const/light=TRAFFIC_LIGHTS[lightIndex]>
44

55
<button onClick() { lightIndex = (lightIndex + 1) % TRAFFIC_LIGHTS.length }>
66
Next light
@@ -9,6 +9,6 @@ static const TRAFFIC_LIGHTS = ["red", "orange", "green"];
99
<p>
1010
You must
1111
<if=light === "red">STOP</if>
12-
<else-if=light === "orange">SLOW DOWN</else-if>
12+
<else if=light === "orange">SLOW DOWN</else>
1313
<else>GO</else>
1414
</p>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<let/pageTitle = ""/>
2-
<effect() { pageTitle = document.title }/>
1+
<let/pageTitle="">
2+
<script>pageTitle = document.title</script>
33
<p>Page title: ${pageTitle}</p>
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<let/time = new Date()/>
2-
<lifecycle
3-
onMount() { this.timer = setInterval(_ => time = new Date(), 1000) }
4-
onDestroy() { clearInterval(this.timer) }
5-
/>
1+
<let/time=new Date()>
2+
<script>
3+
const id = setInterval(() => time = new Date(), 1000);
4+
$signal.onabort = () => clearInterval(id)
5+
</script>
66
<p>Current time: ${time.toLocaleTimeString()}</p>

0 commit comments

Comments
 (0)