Skip to content

Commit

Permalink
Merge pull request #1034 from preactjs/fix/home-repl-examples
Browse files Browse the repository at this point in the history
fix: REPL examples on landing page
  • Loading branch information
rschristian authored Dec 3, 2023
2 parents 9e7798a + 07aa2df commit 2d43d44
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 14 deletions.
15 changes: 11 additions & 4 deletions content/de/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,25 @@ function Counter() {
<div>
<h2>To Do-Listen-Komponente</h2>
<pre><code class="lang-jsx">
export default class ToDoList extends Component {
// --repl
export default class TodoList extends Component {
state = { todos: [], text: '' };
setText = e =&gt; {
this.setState({ text: e.target.value });
};
addToDo = () =&gt; {
addTodo = () =&gt; {
let { todos, text } = this.state;
todos = todos.concat({ text });
this.setState({ todos, text: '' });
};
render({ }, { todos, text }) {
return (
&lt;form onSubmit={this.addToDo} action="javascript:"&gt;
&lt;form onSubmit={this.addTodo} action="javascript:"&gt;
&lt;label&gt;
&lt;span&gt;Add Todo&lt;/span&gt;
&lt;input value={text} onInput={this.setText} /&gt;
&lt;/label&gt;
&lt;button type="submit"&gt;Add&lt;/button&gt;
&lt;ul&gt;
{ todos.map( todo =&gt; (
&lt;li&gt;{todo.text}&lt;/li&gt;
Expand All @@ -167,6 +169,8 @@ export default class ToDoList extends Component {
);
}
}
// --repl-after
render(&lt;TodoList /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand All @@ -187,20 +191,23 @@ render(&lt;ToDoList /&gt;, document.body);
<div>
<h2>Zeige GitHub-Stars</h2>
<pre><code class="lang-jsx">
// --repl
export default class Stars extends Component {
async componentDidMount() {
let stars = await githubStars(this.props.repo);
this.setState({ stars });
}
render({ repo }, { stars=0 }) {
let url = \`https://github.com/${repo}\`;
let url = `https://github.com/${repo}`;
return (
&lt;a href={url} class="stars"&gt;
⭐️ {stars} Stars
&lt;/a&gt;
);
}
}
// --repl-after
render(&lt;Stars /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand Down
6 changes: 6 additions & 0 deletions content/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function Counter() {
<div>
<h2>Todo List</h2>
<pre><code class="lang-jsx">
// --repl
export default class TodoList extends Component {
state = { todos: [], text: '' };
setText = e =&gt; {
Expand Down Expand Up @@ -165,6 +166,8 @@ export default class TodoList extends Component {
);
}
}
// --repl-after
render(&lt;TodoList /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand All @@ -184,6 +187,7 @@ render(&lt;TodoList /&gt;, document.body);
<div>
<h2>Fetch GitHub Stars</h2>
<pre><code class="lang-jsx">
// --repl
export default class Stars extends Component {
async componentDidMount() {
let stars = await githubStars(this.props.repo);
Expand All @@ -198,6 +202,8 @@ export default class Stars extends Component {
);
}
}
// --repl-after
render(&lt;Stars /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand Down
11 changes: 9 additions & 2 deletions content/es/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function Counter() {
<div>
<h2>Componente de Todo List</h2>
<pre><code class="lang-jsx">
// --repl
export default class TodoList extends Component {
state = { todos: [], text: '' };
setText = e =&gt; {
Expand All @@ -161,9 +162,10 @@ export default class TodoList extends Component {
return (
&lt;form onSubmit={this.addTodo} action="javascript:"&gt;
&lt;label&gt;
&lt;span&gt;Add Todo&lt;span&gt;
&lt;span&gt;Add Todo&lt;/span&gt;
&lt;input value={text} onInput={this.setText} /&gt;
&lt;/label&gt;
&lt;button type="submit"&gt;Add&lt;/button&gt;
&lt;ul&gt;
{ todos.map( todo =&gt; (
&lt;li&gt;{todo.text}&lt;/li&gt;
Expand All @@ -173,6 +175,8 @@ export default class TodoList extends Component {
);
}
}
// --repl-after
render(&lt;TodoList /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand All @@ -193,20 +197,23 @@ render(&lt;TodoList /&gt;, document.body);
<div>
<h2>Buscando las estrellas de Github</h2>
<pre><code class="lang-jsx">
// --repl
export default class Stars extends Component {
async componentDidMount() {
let stars = await githubStars(this.props.repo);
this.setState({ stars });
}
render({ repo }, { stars=0 }) {
let url = \`https://github.com/${repo}\`;
let url = `https://github.com/${repo}`;
return (
&lt;a href={url} class="stars"&gt;
⭐️ {stars} Stars
&lt;/a&gt;
);
}
}
// --repl-after
render(&lt;Stars /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand Down
11 changes: 9 additions & 2 deletions content/fr/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function Counter() {
<div>
<h2>Composant liste de tâches</h2>
<pre><code class="lang-jsx">
// --repl
export default class TodoList extends Component {
state = { todos: [], text: '' };
setText = e =&gt; {
Expand All @@ -154,9 +155,10 @@ export default class TodoList extends Component {
return (
&lt;form onSubmit={this.addTodo} action="javascript:"&gt;
&lt;label&gt;
&lt;span&gt;Add Todo&lt;span&gt;
&lt;span&gt;Add Todo&lt;/span&gt;
&lt;input value={text} onInput={this.setText} /&gt;
&lt;/label&gt;
&lt;button type="submit"&gt;Add&lt;/button&gt;
&lt;ul&gt;
{ todos.map( todo =&gt; (
&lt;li&gt;{todo.text}&lt;/li&gt;
Expand All @@ -166,6 +168,8 @@ export default class TodoList extends Component {
);
}
}
// --repl-after
render(&lt;TodoList /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand All @@ -186,20 +190,23 @@ render(&lt;TodoList /&gt;, document.body);
<div>
<h2>Récupérer les Stars Github</h2>
<pre><code class="lang-jsx">
// --repl
export default class Stars extends Component {
async componentDidMount() {
let stars = await githubStars(this.props.repo);
this.setState({ stars });
}
render({ repo }, { stars=0 }) {
let url = \`https://github.com/${repo}\`;
let url = `https://github.com/${repo}`;
return (
&lt;a href={url} class="stars"&gt;
⭐️ {stars} Stars
&lt;/a&gt;
);
}
}
// --repl-after
render(&lt;Stars /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand Down
11 changes: 9 additions & 2 deletions content/it/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function Counter() {
<div>
<h2>Componente Lista delle attività</h2>
<pre><code class="lang-jsx">
// --repl
export default class TodoList extends Component {
state = { todos: [], text: '' };
setText = e =&gt; {
Expand All @@ -161,9 +162,10 @@ export default class TodoList extends Component {
return (
&lt;form onSubmit={this.addTodo} action="javascript:"&gt;
&lt;label&gt;
&lt;span&gt;Add Todo&lt;span&gt;
&lt;span&gt;Add Todo&lt;/span&gt;
&lt;input value={text} onInput={this.setText} /&gt;
&lt;/label&gt;
&lt;button type="submit"&gt;Add&lt;/button&gt;
&lt;ul&gt;
{ todos.map( todo =&gt; (
&lt;li&gt;{todo.text}&lt;/li&gt;
Expand All @@ -173,6 +175,8 @@ export default class TodoList extends Component {
);
}
}
// --repl-after
render(&lt;TodoList /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand All @@ -193,20 +197,23 @@ render(&lt;TodoList /&gt;, document.body);
<div>
<h2>Visualizzare le stelle su GitHub</h2>
<pre><code class="lang-jsx">
// --repl
export default class Stars extends Component {
async componentDidMount() {
let stars = await githubStars(this.props.repo);
this.setState({ stars });
}
render({ repo }, { stars=0 }) {
let url = \`https://github.com/${repo}\`;
let url = `https://github.com/${repo}`;
return (
&lt;a href={url} class="stars"&gt;
⭐️ {stars} Stars
&lt;/a&gt;
);
}
}
// --repl-after
render(&lt;Stars /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand Down
6 changes: 6 additions & 0 deletions content/ja/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function Counter() {
<div>
<h2>Todoリスト</h2>
<pre><code class="lang-jsx">
// --repl
export default class TodoList extends Component {
state = { todos: [], text: '' };
setText = e =&gt; {
Expand Down Expand Up @@ -164,6 +165,8 @@ export default class TodoList extends Component {
);
}
}
// --repl-after
render(&lt;TodoList /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand All @@ -183,6 +186,7 @@ render(&lt;TodoList /&gt;, document.body);
<div>
<h2>GitHubのスター数を取得</h2>
<pre><code class="lang-jsx">
// --repl
export default class Stars extends Component {
async componentDidMount() {
let stars = await githubStars(this.props.repo);
Expand All @@ -197,6 +201,8 @@ export default class Stars extends Component {
);
}
}
// --repl-after
render(&lt;Stars /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand Down
6 changes: 6 additions & 0 deletions content/kr/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ function Counter() {
<div>
<h2>Todo 리스트</h2>
<pre><code class="lang-jsx">
// --repl
export default class TodoList extends Component {
state = { todos: [], text: '' };
setText = e =&gt; {
Expand Down Expand Up @@ -160,6 +161,8 @@ export default class TodoList extends Component {
);
}
}
// --repl-after
render(&lt;TodoList /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand All @@ -179,6 +182,7 @@ render(&lt;TodoList /&gt;, document.body);
<div>
<h2>GitHub Star 가져오기</h2>
<pre><code class="lang-jsx">
// --repl
export default class Stars extends Component {
async componentDidMount() {
let stars = await githubStars(this.props.repo);
Expand All @@ -193,6 +197,8 @@ export default class Stars extends Component {
);
}
}
// --repl-after
render(&lt;Stars /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand Down
11 changes: 9 additions & 2 deletions content/pt-br/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function Counter() {
<div>
<h2>Componente de <i>Todo List</i> </h2>
<pre><code class="lang-jsx">
// --repl
export default class TodoList extends Component {
state = { todos: [], text: '' };
setText = e =&gt; {
Expand All @@ -151,9 +152,10 @@ export default class TodoList extends Component {
return (
&lt;form onSubmit={this.addTodo} action="javascript:"&gt;
&lt;label&gt;
&lt;span&gt;Add Todo&lt;span&gt;
&lt;span&gt;Add Todo&lt;/span&gt;
&lt;input value={text} onInput={this.setText} /&gt;
&lt;/label&gt;
&lt;button type="submit"&gt;Add&lt;/button&gt;
&lt;ul&gt;
{ todos.map( todo =&gt; (
&lt;li&gt;{todo.text}&lt;/li&gt;
Expand All @@ -163,6 +165,8 @@ export default class TodoList extends Component {
);
}
}
// --repl-after
render(&lt;TodoList /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand All @@ -183,20 +187,23 @@ render(&lt;TodoList /&gt;, document.body);
<div>
<h2>Buscar estrelas no Github</h2>
<pre><code class="lang-jsx">
// --repl
export default class Stars extends Component {
async componentDidMount() {
let stars = await githubStars(this.props.repo);
this.setState({ stars });
}
render({ repo }, { stars=0 }) {
let url = \`https://github.com/${repo}\`;
let url = `https://github.com/${repo}`;
return (
&lt;a href={url} class="stars"&gt;
⭐️ {stars} Stars
&lt;/a&gt;
);
}
}
// --repl-after
render(&lt;Stars /&gt;, document.getElementById("app"));
</code></pre>
</div>
<div>
Expand Down
Loading

0 comments on commit 2d43d44

Please sign in to comment.