Skip to content

Commit

Permalink
chore: add some hidden examples for debugging to the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeen committed Nov 2, 2023
1 parent f7fec45 commit df9f16e
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
19 changes: 19 additions & 0 deletions tests/dummy/app/components/docs/queued.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<DocsDemo as |demo|>
<demo.example @name='queued.hbs'>

{{#if (sound-is-playing (current-sound))}}
<p>{{get (current-sound) 'url'}}</p>

<button type='button' {{on 'click' (stop-sound (current-sound))}}>
Stop
</button>
{{else}}
<button type='button' {{on 'click' this.playSound}}>
Play Queue
</button>
{{/if}}

</demo.example>
<demo.snippet @name='queued.hbs' />
<demo.snippet @name='queued.js' />
</DocsDemo>
41 changes: 41 additions & 0 deletions tests/dummy/app/components/docs/queued.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
// BEGIN-SNIPPET queued.js
export default class Queued extends Component {
@service stereo;

@tracked identifier;
@tracked queue = [];

@action
async playSound() {
this.queue = [
'/sounds/attention.mp3',
'/sounds/internet-on-computers.mp3',
'https://kut.streamguys1.com/kut-web.aac',
];

let sound = await this.playNext();
sound.audioElement.setAttribute(
'id',
`id-${Math.floor(Math.random() * 10000)}`
);

this.stereo.on('audio-ended', ({ sound }) => {
console.log(sound.audioElement);
this.playNext();
});
}

async playNext() {
let next = this.queue.shift();
if (next) {
let { sound } = await this.stereo.play(next);

return sound;
}
}
}
// END-SNIPPET queued.js
1 change: 1 addition & 0 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Router.map(function () {
this.route('volume');
this.route('advanced');
this.route('testing');
this.route('debugging');
});

this.route('diagnostic', function () {
Expand Down
3 changes: 0 additions & 3 deletions tests/dummy/app/templates/docs/advanced.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
Modifiers to create position controls
<Docs::CustomPositionControl @identifier="/sounds/works-just-like-a-vcr.mp3"/>

Proxies
<Docs::ProxyExample/>
5 changes: 5 additions & 0 deletions tests/dummy/app/templates/docs/debugging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Proxies
<Docs::ProxyExample/>

Queued
<Docs::Queued/>

0 comments on commit df9f16e

Please sign in to comment.