Skip to content

Commit 73ffab2

Browse files
committed
Updated diff markers to gts snippets
1 parent ef8b5f3 commit 73ffab2

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

guides/release/typescript/core-concepts/invokables.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ What elements do we need to build a signature for this component?
115115

116116
We can define a signature with those `Args` on it and apply it to the component definition by adding it as a type parameter to the `extends Component` clause:
117117

118-
```gts {data-filename="app/components/audio-player.gts" }
118+
```gts { data-filename="app/components/audio-player.gts" data-diff="+6,+7,+8,+9,+10,+11,-13,+14" }
119119
import Component from '@glimmer/component';
120120
import { tracked } from '@glimmer/tracking';
121121
import playWhen from '../modifiers/play-when.ts';
@@ -128,6 +128,7 @@ interface AudioPlayerSignature {
128128
};
129129
}
130130
131+
export default class AudioPlayer extends Component {
131132
export default class AudioPlayer extends Component<AudioPlayerSignature> {
132133
@tracked isPlaying = false;
133134
@@ -145,11 +146,12 @@ export default class AudioPlayer extends Component<AudioPlayerSignature> {
145146
<button type='button' {{on 'click' this.play}}>Play</button>
146147
<button type='button' {{on 'click' this.pause}}>Pause</button>
147148
</template>
149+
}
148150
```
149151

150152
Now, let's expand on this example to give callers the ability to apply attributes to the audio element with an `Element`:
151153

152-
```gts {data-filename="app/components/audio-player.gts" }
154+
```gts { data-filename="app/components/audio-player.gts" data-diff="+11,-26,+27" }
153155
import Component from '@glimmer/component';
154156
import { tracked } from '@glimmer/tracking';
155157
import playWhen from '../modifiers/play-when.ts';
@@ -161,7 +163,6 @@ interface AudioPlayerSignature {
161163
srcUrl: string;
162164
};
163165
Element: HTMLAudioElement;
164-
165166
}
166167
167168
export default class AudioPlayer extends Component<AudioPlayerSignature> {
@@ -176,16 +177,18 @@ export default class AudioPlayer extends Component<AudioPlayerSignature> {
176177
};
177178
178179
<template>
180+
<audio src={{@srcURL}} {{playWhen this.isPlaying}} />
179181
<audio ...attributes src={{@srcURL}} {{playWhen this.isPlaying}} />
180182
181183
<button type='button' {{on 'click' this.play}}>Play</button>
182184
<button type='button' {{on 'click' this.pause}}>Pause</button>
183185
</template>
186+
}
184187
```
185188

186189
We can also let the user provide a fallback for the case where the audio element does not load, using the default block. We have to name the default block explicitly in the new `Blocks` type we add to our signature. Since blocks yield out a list of items, we can use a [tuple type][tuple] to represent them. In this case, we will just yield out the same URL we loaded, to let the caller use it for the fallback.
187190

188-
```gts {data-filename="app/components/audio-player.gts" }
191+
```gts { data-filename="app/components/audio-player.gts" data-diff="+11,+12,+13,-29,+30,+31,+32" }
189192
import Component from '@glimmer/component';
190193
import { tracked } from '@glimmer/tracking';
191194
import playWhen from '../modifiers/play-when.ts';
@@ -214,21 +217,24 @@ export default class AudioPlayer extends Component<AudioPlayerSignature> {
214217
};
215218
216219
<template>
220+
<audio ...attributes src={{@srcURL}} {{playWhen this.isPlaying}} />
217221
<audio ...attributes src={{@srcURL}} {{playWhen this.isPlaying}}>
218222
{{yield @srcUrl}}
219223
</audio>
220224
221225
<button type='button' {{on 'click' this.play}}>Play</button>
222226
<button type='button' {{on 'click' this.pause}}>Pause</button>
223227
</template>
228+
}
229+
224230
```
225231

226232

227233
Let's go one step further and switch to supporting for two [named blocks][named-blocks]: an optional `title` block for a caption for the audio element, and a `fallback` block for the audio fallback where we previously used a `default` block.
228234

229235
To represent this, we will update the `default` block to be named `fallback` instead and add the `title` block. We do not yield anything to the `title` block, so we use an empty tuple, `[]`, to represent it.
230236

231-
```gts {data-filename="app/components/audio-player.gts" }
237+
```gts {data-filename="app/components/audio-player.gts" data-diff="-12,+13,+14,-31,-32,-33,+34,+35,+36,+37,+38,+39,+40,+41" }
232238
import Component from '@glimmer/component';
233239
import { tracked } from '@glimmer/tracking';
234240
import playWhen from '../modifiers/play-when.ts';
@@ -240,6 +246,7 @@ interface AudioPlayerSignature {
240246
srcUrl: string;
241247
};
242248
Blocks: {
249+
default: [srcUrl: string];
243250
fallback: [srcUrl: string];
244251
title: [];
245252
};
@@ -258,6 +265,9 @@ export default class AudioPlayer extends Component<AudioPlayerSignature> {
258265
};
259266
260267
<template>
268+
<audio ...attributes src={{@srcURL}} {{playWhen this.isPlaying}}>
269+
{{yield @srcUrl}}
270+
</audio>
261271
<figure>
262272
{{#if (has-block 'title')}}
263273
<figcaption>{{yield to='title'}}</figcaption>
@@ -270,6 +280,7 @@ export default class AudioPlayer extends Component<AudioPlayerSignature> {
270280
<button type='button' {{on 'click' this.play}}>Play</button>
271281
<button type='button' {{on 'click' this.pause}}>Pause</button>
272282
</template>
283+
}
273284
```
274285

275286
### Types in JavaScript with JSDoc
@@ -327,6 +338,7 @@ import { on } from '@ember/modifier';
327338
<button type='button' {{on 'click' this.play}}>Play</button>
328339
<button type='button' {{on 'click' this.pause}}>Pause</button>
329340
</template>
341+
}
330342
```
331343

332344
## Classic Ember Components

0 commit comments

Comments
 (0)