Skip to content

Commit

Permalink
qwik的函数提取需要 $()语法
Browse files Browse the repository at this point in the history
  • Loading branch information
chen56 committed Aug 15, 2023
1 parent 0645977 commit 6f470b7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
5 changes: 1 addition & 4 deletions spaces/music_note/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import { Link } from '@builder.io/qwik-city';
export default component$(() => {
return (
<>
<h1>Hi 👋</h1>
<h1>Home 👋</h1>
<p>
Can't wait to see what you build with qwik!
<br />
Happy coding.
</p>

<p><a href="/webaudio" class="my-link"> webaudio </a></p>
<p><a href="/web_audio_api" class="my-link"> web audio api </a></p>
</>
);
});
Expand Down
2 changes: 1 addition & 1 deletion spaces/music_note/src/routes/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default component$(() => {
return <>
<header>
<ul>
<li> <a href="/webaudio" class="my-link"> webaudio </a> </li>
<li> <a href="/music" class="my-link"> music </a> </li>
<li> <a href="/web_audio_api" class="my-link"> web audio api </a> </li>
</ul>
</header>
Expand Down
4 changes: 2 additions & 2 deletions spaces/music_note/src/routes/music/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export default component$(() => {
const playState = useSignal(false);

return <div>
<h1>tonejs</h1>
<h2>example 1</h2>
<h1>music</h1>
<h2>example: 播放音符</h2>
play:
<button
onClick$={() => {
Expand Down
21 changes: 10 additions & 11 deletions spaces/music_note/src/routes/web_audio_api/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { component$, type Signal, useSignal } from '@builder.io/qwik';
import { component$, type Signal, useSignal, $ } from '@builder.io/qwik';
import * as Tone from 'tone'


export default component$(() => {

const playState = useSignal(false);

const play = $(() => {
const synth = new Tone.Synth().toDestination();
const now = Tone.now();
synth.triggerAttackRelease("C4", "8n");
playState.value = !playState.value;
});

return <div>
<h1>web audio api</h1>

<h2>example 1</h2>
play <button
onClick$={() => {
const synth = new Tone.Synth().toDestination();
const now = Tone.now()
synth.triggerAttackRelease("C4", "8n");
playState.value = !playState.value;
}}>
▶︎
</button>
play <button onClick$={play}> ▶︎ </button>
</div>;
});

0 comments on commit 6f470b7

Please sign in to comment.