-
-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Better align REPL examples for comparison (#1164)
* refactor: Better align REPL examples for comparison * chore: Additional formatting * refactor: Switch to pointer events in spiral to support mobile
- Loading branch information
1 parent
244841d
commit ccab39c
Showing
17 changed files
with
316 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
src/components/controllers/repl/examples/counter-with-htm.txt
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
src/components/controllers/repl/examples/counters/counter-hooks.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { render } from 'preact'; | ||
import { useState } from 'preact/hooks'; | ||
|
||
function Counter() { | ||
const [count, setCount] = useState(0); | ||
|
||
return ( | ||
<div class="counter-container"> | ||
<button onClick={() => setCount(count + 1)}>Increment</button> | ||
<input readonly value={count} /> | ||
<button onClick={() => setCount(count - 1)}>Decrement</button> | ||
</div> | ||
); | ||
} | ||
|
||
render(<Counter />, document.getElementById('app')); |
17 changes: 17 additions & 0 deletions
17
src/components/controllers/repl/examples/counters/counter-htm.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { render } from 'preact'; | ||
import { useState } from 'preact/hooks'; | ||
import { html } from 'htm/preact'; | ||
|
||
export function Counter() { | ||
const [count, setCount] = useState(0); | ||
|
||
return html` | ||
<div class="counter-container"> | ||
<button onClick=${() => setCount(count + 1)}>Increment</button> | ||
<input readonly value=${count} /> | ||
<button onClick=${() => setCount(count - 1)}>Decrement</button> | ||
</div> | ||
`; | ||
} | ||
|
||
render(<Counter />, document.getElementById('app')); |
16 changes: 16 additions & 0 deletions
16
src/components/controllers/repl/examples/counters/counter-signals.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { render } from 'preact'; | ||
import { signal } from '@preact/signals'; | ||
|
||
const count = signal(0); | ||
|
||
function Counter() { | ||
return ( | ||
<div class="counter-container"> | ||
<button onClick={() => count.value++}>Increment</button> | ||
<input readonly value={count} /> | ||
<button onClick={() => count.value--}>Decrement</button> | ||
</div> | ||
); | ||
} | ||
|
||
render(<Counter />, document.getElementById('app')); |
21 changes: 21 additions & 0 deletions
21
src/components/controllers/repl/examples/counters/counter.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Component, render } from 'preact'; | ||
|
||
class Counter extends Component { | ||
state = { count: 0 }; | ||
|
||
render({}, { count }) { | ||
return ( | ||
<div class="counter-container"> | ||
<button onClick={() => this.setState({ count: count + 1 })}> | ||
Increment | ||
</button> | ||
<input readonly value={count} /> | ||
<button onClick={() => this.setState({ count: count - 1 })}> | ||
Decrement | ||
</button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
render(<Counter />, document.getElementById('app')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Counters | ||
import simpleCounterExample from './counters/counter.txt?url'; | ||
import simpleCounterHooksExample from './counters/counter-hooks.txt?url'; | ||
import simpleCounterSignalsExample from './counters/counter-signals.txt?url'; | ||
import simpleCounterHTMExample from './counters/counter-htm.txt?url'; | ||
|
||
// Todo Lists | ||
import todoExample from './todo-lists/todo-list.txt?url'; | ||
import todoSignalExample from './todo-lists/todo-list-signals.txt?url'; | ||
|
||
import repoListExample from './github-repo-list.txt?url'; | ||
import contextExample from './context.txt?url'; | ||
import spiralExample from './spiral.txt?url'; | ||
|
||
export const EXAMPLES = [ | ||
{ | ||
group: 'Simple Counters', | ||
items: [ | ||
{ | ||
name: 'Simple Counter', | ||
slug: 'counter', | ||
url: simpleCounterExample | ||
}, | ||
{ | ||
name: 'Simple Counter (Hooks)', | ||
slug: 'counter-hooks', | ||
url: simpleCounterHooksExample | ||
}, | ||
{ | ||
name: 'Simple Counter (Signals)', | ||
slug: 'counter-signals', | ||
url: simpleCounterSignalsExample | ||
}, | ||
{ | ||
name: 'Simple Counter (HTM)', | ||
slug: 'counter-htm', | ||
url: simpleCounterHTMExample | ||
} | ||
] | ||
}, | ||
{ | ||
group: 'Todo Lists', | ||
items: [ | ||
{ | ||
name: 'Todo List', | ||
slug: 'todo', | ||
url: todoExample | ||
}, | ||
{ | ||
name: 'Todo List (Signals)', | ||
slug: 'todo-signals', | ||
url: todoSignalExample | ||
} | ||
] | ||
}, | ||
{ | ||
name: 'Github Repo List', | ||
slug: 'github-repo-list', | ||
url: repoListExample | ||
}, | ||
{ | ||
name: 'Context', | ||
slug: 'context', | ||
url: contextExample | ||
}, | ||
{ | ||
group: 'Animation', | ||
items: [ | ||
{ | ||
name: 'Spiral', | ||
slug: 'spiral', | ||
url: spiralExample | ||
} | ||
] | ||
} | ||
]; | ||
|
||
export function getExample(slug, list = EXAMPLES) { | ||
for (let i = 0; i < list.length; i++) { | ||
let item = list[i]; | ||
if (item.group) { | ||
let found = getExample(slug, item.items); | ||
if (found) return found; | ||
} else if (item.slug.toLowerCase() === slug.toLowerCase()) { | ||
return item; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param {string} slug | ||
*/ | ||
export async function fetchExample(slug) { | ||
const example = getExample(slug); | ||
if (!example) return; | ||
return await fetch(example.url).then(r => r.text()); | ||
} |
16 changes: 0 additions & 16 deletions
16
src/components/controllers/repl/examples/simple-counter.txt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/components/controllers/repl/examples.css → ...nents/controllers/repl/examples/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.