Skip to content

Commit 5e03cca

Browse files
bleucitronRomain Crestey
andcommitted
docs: 03-01 (#19)
* docs: 03-01 * docs: remove duplicate * docs: add s * docs: test link in .js comment * docs: add links --------- Co-authored-by: Romain Crestey <[email protected]>
1 parent d403046 commit 5e03cca

File tree

5 files changed

+65
-52
lines changed

5 files changed

+65
-52
lines changed

documentation/docs/03-runtime/01-svelte.md

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
title: svelte
33
---
44

5-
The `svelte` package exposes [lifecycle functions](https://learn.svelte.dev/tutorial/onmount) and the [context API](https://learn.svelte.dev/tutorial/context-api).
5+
Le paquet `svelte` expose les [fonctions de cycle de vie](https://learn.svelte.dev/tutorial/onmount) et l'[API de contexte](https://learn.svelte.dev/tutorial/context-api).
66

77
## `onMount`
88

99
> EXPORT_SNIPPET: svelte#onMount
1010
11-
The `onMount` function schedules a callback to run as soon as the component has been mounted to the DOM. It must be called during the component's initialisation (but doesn't need to live _inside_ the component; it can be called from an external module).
11+
La fonction `onMount` permet de planifier l'exécution d'un <span class="vo">[callback](/docs/development#callback)</span> dès que le composant a été monté dans le <span class="vo">[DOM](/docs/web#dom)</span>. Elle doit être appelée pendant l'instantiation du composant (mais elle n'a pas besoin d'être définie _à l'intérieur_ du composant ; elle peut être appelée depuis un module externe).
1212

13-
`onMount` does not run inside a [server-side component](/docs/server-side-component-api).
13+
`onMount` n'est pas exécutée pas à l'intérieur d'un [composant serveur](/docs/server-side-component-api).
1414

1515
```svelte
1616
<script>
1717
import { onMount } from 'svelte';
1818
1919
onMount(() => {
20-
console.log('the component has mounted');
20+
console.log('le composant est monté');
2121
});
2222
</script>
2323
```
2424

25-
If a function is returned from `onMount`, it will be called when the component is unmounted.
25+
Si une fonction est renvoyée par `onMount`, celle-ci sera appelée lorsque le composant sera démonté.
2626

2727
```svelte
2828
<script>
@@ -38,22 +38,22 @@ If a function is returned from `onMount`, it will be called when the component i
3838
</script>
3939
```
4040

41-
> This behaviour will only work when the function passed to `onMount` _synchronously_ returns a value. `async` functions always return a `Promise`, and as such cannot _synchronously_ return a function.
41+
> Ce comportement ne fonctionne que si la fonction passée à `onMount` renvoie une valeur de manière _synchrone_. Les fonctions `async` renvoient toujours une `Promise`, ce qui implique qu'elles ne peuvent jamais renvoyer une fonction de manière _synchrone_.
4242
4343
## `beforeUpdate`
4444

4545
> EXPORT_SNIPPET: svelte#beforeUpdate
4646
47-
Schedules a callback to run immediately before the component is updated after any state change.
47+
Planifie l'exécution d'un <span class="vo">[callback](/docs/development#callback)</span> immédiatement avant la mise à jour du composant, lorsqu'un changement d'état s'est produit.
4848

49-
> The first time the callback runs will be before the initial `onMount`
49+
> La première exécution du <span class="vo">[callback](/docs/development#callback)</span> se produit juste avant l'appel du `onMount` initial.
5050
5151
```svelte
5252
<script>
5353
import { beforeUpdate } from 'svelte';
5454
5555
beforeUpdate(() => {
56-
console.log('the component is about to update');
56+
console.log('le composant est sur le point de se mettre à jour');
5757
});
5858
</script>
5959
```
@@ -62,16 +62,16 @@ Schedules a callback to run immediately before the component is updated after an
6262

6363
> EXPORT_SNIPPET: svelte#afterUpdate
6464
65-
Schedules a callback to run immediately after the component has been updated.
65+
Planifie un <span class="vo">[callback](/docs/development#callback)</span> à exécuter immédiatement après la mise à jour du composant.
6666

67-
> The first time the callback runs will be after the initial `onMount`
67+
> La première exécution du <span class="vo">[callback](/docs/development#callback)</span> se produit juste après l'appel du `onMount` initial.
6868
69-
```svelte
69+
```sv
7070
<script>
7171
import { afterUpdate } from 'svelte';
7272
7373
afterUpdate(() => {
74-
console.log('the component just updated');
74+
console.log("le composant vient d'être mis à jour");
7575
});
7676
</script>
7777
```
@@ -80,16 +80,16 @@ Schedules a callback to run immediately after the component has been updated.
8080

8181
> EXPORT_SNIPPET: svelte#onDestroy
8282
83-
Schedules a callback to run immediately before the component is unmounted.
83+
Planifie un <span class="vo">[callback](/docs/development#callback)</span> à exécuter immédiatement avant que le composant ne soit démonté.
8484

85-
Out of `onMount`, `beforeUpdate`, `afterUpdate` and `onDestroy`, this is the only one that runs inside a server-side component.
85+
Parmi les <span class="vo">[callbacks](/docs/development#callback)</span> de `onMount`, `beforeUpdate`, `afterUpdate` et `onDestroy`, c'est le seul qui s'exécute dans un composant côté serveur.
8686

8787
```svelte
8888
<script>
8989
import { onDestroy } from 'svelte';
9090
9191
onDestroy(() => {
92-
console.log('the component is being destroyed');
92+
console.log('le composant va être détruit');
9393
});
9494
</script>
9595
```
@@ -98,16 +98,16 @@ Out of `onMount`, `beforeUpdate`, `afterUpdate` and `onDestroy`, this is the onl
9898

9999
> EXPORT_SNIPPET: svelte#tick
100100
101-
Returns a promise that resolves once any pending state changes have been applied, or in the next microtask if there are none.
101+
Renvoie une promesse qui se résout une fois que tous les changements d'état en attente ont été appliqués, ou dans la micro-tâche suivante s'il n'y en a pas.
102102

103103
```svelte
104104
<script>
105105
import { beforeUpdate, tick } from 'svelte';
106106
107107
beforeUpdate(async () => {
108-
console.log('the component is about to update');
108+
console.log('le composant est sur le point de se mettre à jour');
109109
await tick();
110-
console.log('the component just updated');
110+
console.log('le composant vient de se mettre à jour');
111111
});
112112
</script>
113113
```
@@ -116,9 +116,9 @@ Returns a promise that resolves once any pending state changes have been applied
116116

117117
> EXPORT_SNIPPET: svelte#setContext
118118
119-
Associates an arbitrary `context` object with the current component and the specified `key` and returns that object. The context is then available to children of the component (including slotted content) with `getContext`.
119+
Associe un objet `context` arbitraire au composant courant et à la `key` spécifiée, puis retourne cet objet. Le contexte est alors accessible pour les enfants du composant (y compris le contenu de <span class="vo">[slot](/docs/sveltejs#slot)</span>) avec `getContext`.
120120

121-
Like lifecycle functions, this must be called during component initialisation.
121+
Comme les fonctions de cycle de vie, elle doit être appelée pendant l'instantiation du composant.
122122

123123
```svelte
124124
<script>
@@ -128,13 +128,13 @@ Like lifecycle functions, this must be called during component initialisation.
128128
</script>
129129
```
130130

131-
> Context is not inherently reactive. If you need reactive values in context then you can pass a store into context, which _will_ be reactive.
131+
> Le contexte n'est pas intrinsèquement réactif. Si vous avez besoin de valeurs réactives dans le contexte, alors vous pouvez passer un store dans le contexte, store qui _sera_ réactif.
132132
133133
## `getContext`
134134

135135
> EXPORT_SNIPPET: svelte#getContext
136136
137-
Retrieves the context that belongs to the closest parent component with the specified `key`. Must be called during component initialisation.
137+
Récupère le contexte qui appartient au composant parent le plus proche avec la `key` spécifiée. Doit être appelé pendant l'instantiation du composant.
138138

139139
```svelte
140140
<script>
@@ -148,14 +148,14 @@ Retrieves the context that belongs to the closest parent component with the spec
148148

149149
> EXPORT_SNIPPET: svelte#hasContext
150150
151-
Checks whether a given `key` has been set in the context of a parent component. Must be called during component initialisation.
151+
Vérifie si une clé donnée a été définie dans le contexte d'un composant parent. Doit être appelé pendant l'instantiation du composant.
152152

153153
```svelte
154154
<script>
155155
import { hasContext } from 'svelte';
156156
157157
if (hasContext('answer')) {
158-
// do something
158+
// faites quelque chose
159159
}
160160
</script>
161161
```
@@ -164,7 +164,7 @@ Checks whether a given `key` has been set in the context of a parent component.
164164

165165
> EXPORT_SNIPPET: svelte#getAllContexts
166166
167-
Retrieves the whole context map that belongs to the closest parent component. Must be called during component initialisation. Useful, for example, if you programmatically create a component and want to pass the existing context to it.
167+
Récupère l'ensemble des contextes appartenant au composant parent le plus proche. Doit être appelé pendant l'instantiation du composant. Utile, par exemple, si vous créez un composant de manière programmatique et que vous voulez lui passer le contexte existant.
168168

169169
```svelte
170170
<script>
@@ -178,9 +178,9 @@ Retrieves the whole context map that belongs to the closest parent component. Mu
178178

179179
> EXPORT_SNIPPET: svelte#createEventDispatcher
180180
181-
Creates an event dispatcher that can be used to dispatch [component events](/docs/component-directives#on-eventname). Event dispatchers are functions that can take two arguments: `name` and `detail`.
181+
Crée un générateur d'événements qui peut être utilisé pour distribuer les [événements de composants] (/docs#template-syntaxe-component-directives-on-eventname). Les générateurs d'événements sont des fonctions qui peuvent prendre deux arguments : `name` et `detail`.
182182

183-
Component events created with `createEventDispatcher` create a [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent). These events do not [bubble](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#Event_bubbling_and_capture). The `detail` argument corresponds to the [CustomEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail) property and can contain any type of data.
183+
Les événements de composants créés avec `createEventDispatcher` créent un [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent) (en anglais). Ces événements ne suivent pas la chaîne de <span class="vo">[bubbling](/docs/javascript#bubble-capture-bubble)</span>. L'argument `detail` correspond à la propriété [CustomEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail) (en anglais) et peut contenir tout type de données.
184184

185185
```svelte
186186
<script>
@@ -189,22 +189,22 @@ Component events created with `createEventDispatcher` create a [CustomEvent](htt
189189
const dispatch = createEventDispatcher();
190190
</script>
191191
192-
<button on:click={() => dispatch('notify', 'detail value')}>Fire Event</button>
192+
<button on:click="{() => dispatch('notify', 'detail value')}">Générer un événement</button>
193193
```
194194

195-
Events dispatched from child components can be listened to in their parent. Any data provided when the event was dispatched is available on the `detail` property of the event object.
195+
Les événements envoyés par les composants enfants peuvent être écoutés par leur parent. Toutes les données fournies lors de l'envoi de l'événement sont disponibles dans la propriété `detail` de l'objet événement.
196196

197197
```svelte
198198
<script>
199199
function callbackFunction(event) {
200-
console.log(`Notify fired! Detail: ${event.detail}`);
200+
console.log(`Événement généré ! Détail: ${event.detail}`)
201201
}
202202
</script>
203203
204-
<Child on:notify={callbackFunction} />
204+
<Child on:notify="{callbackFunction}"/>
205205
```
206206

207-
Events can be cancelable by passing a third parameter to the dispatch function. The function returns `false` if the event is cancelled with `event.preventDefault()`, otherwise it returns `true`.
207+
Les événements peuvent être annulables en passant un troisième paramètre à la fonction `dispatch`. La fonction renvoie `false` si l'événement est annulé avec `event.preventDefault()`, sinon elle renvoie `true`.
208208

209209
```svelte
210210
<script>
@@ -215,15 +215,16 @@ Events can be cancelable by passing a third parameter to the dispatch function.
215215
function notify() {
216216
const shouldContinue = dispatch('notify', 'detail value', { cancelable: true });
217217
if (shouldContinue) {
218-
// no one called preventDefault
218+
// personne n'a appelé preventDefault
219219
} else {
220-
// a listener called preventDefault
220+
// un listener a appelé preventDefault
221221
}
222222
}
223223
</script>
224224
```
225225

226-
You can type the event dispatcher to define which events it can receive. This will make your code more type safe both within the component (wrong calls are flagged) and when using the component (types of the events are now narrowed). See [here](typescript#script-lang-ts-events) how to do it.
226+
Vous pouvez typer le générateur d'évènement pour définir quels évènements il peut recevoir. Cela rendra votre
227+
code plus solide à la fois dans le composant (les mauvais appels seront mis en valeur) et lorsque vous utiliserez le composant (les types d'évènements seront réduits). Voir [cette section](typescript#script-lang-ts-events) pour plus de détail.
227228

228229
## Types
229230

documentation/docs/07-glossary/01-development.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ Vous trouverez plus de détails sur les [getters](https://developer.mozilla.org/
6868

6969
> Bientôt...
7070
71+
## Intellisense
72+
73+
> Bientôt...
74+
7175
## Issue
7276

7377
> Bientôt...

documentation/docs/07-glossary/03-javascript.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,7 @@ Une valeur _nullish_ est une valeur qui est `null` ou `undefined`.
108108

109109
Pour en savoir plus sur la différence entre `null` et `undefined`, vous pouvez par exemple lire [ceci](https://stackoverflow.com/questions/5076944/what-is-the-difference-between-null-and-undefined-in-javascript) (en anglais).
110110

111+
112+
## Shadow DOM
113+
114+
> Bientôt...

packages/svelte/src/runtime/internal/dev.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,22 +270,26 @@ export function construct_svelte_component_dev(component, props) {
270270
}
271271

272272
/**
273-
* Base class for Svelte components with some minor dev-enhancements. Used when dev=true.
273+
* Classe de base pour les composants Svelte avec quelques améliorations mineures. Utilisé lorsque `dev=true`.
274274
*
275-
* Can be used to create strongly typed Svelte components.
275+
* Peut être utilisé pour créer des composants Svelte fortement typés.
276276
*
277-
* #### Example:
277+
* #### Exemple :
278+
*
279+
* Vous avez une librairie de composants sur [npm](https://www.npmjs.com/) appelée `component-library`,
280+
* depuis laquelle vous exportez un composant appelé `MyComponent`. Pour les personnes
281+
* qui utilisent Svelte avec Typescript, vous voulez fournir du typage.
282+
* Vous créez donc un `index.d.ts` :
278283
*
279-
* You have component library on npm called `component-library`, from which
280-
* you export a component called `MyComponent`. For Svelte+TypeScript users,
281-
* you want to provide typings. Therefore you create a `index.d.ts`:
282284
* ```ts
283285
* import { SvelteComponent } from "svelte";
284286
* export class MyComponent extends SvelteComponent<{foo: string}> {}
285287
* ```
286-
* Typing this makes it possible for IDEs like VS Code with the Svelte extension
287-
* to provide intellisense and to use the component like this in a Svelte file
288-
* with TypeScript:
288+
*
289+
* Typer ceci permet aux <span class='vo'>[IDEs](/docs/development#ide)</span> comme VS Code qui ont l'extension Svelte de fournir
290+
* de l'<span class='vo'>[Intellisense](/docs/development#intellisense)</span>, et vous pouvez alors utiliser le composant de cette manière dans un
291+
* fichier Svelte avec Typescript :
292+
*
289293
* ```svelte
290294
* <script lang="ts">
291295
* import { MyComponent } from "component-library";
@@ -349,7 +353,7 @@ export class SvelteComponentDev extends SvelteComponent {
349353
* @template {Record<string, any>} [Props=any]
350354
* @template {Record<string, any>} [Events=any]
351355
* @template {Record<string, any>} [Slots=any]
352-
* @deprecated Use `SvelteComponent` instead. See PR for more information: https://github.com/sveltejs/svelte/pull/8512
356+
* @deprecated Utilisez plutôt `SvelteComponent`. Voir la PR plus d'informations : https://github.com/sveltejs/svelte/pull/8512
353357
* @extends {SvelteComponentDev<Props, Events, Slots>}
354358
*/
355359
export class SvelteComponentTyped extends SvelteComponentDev {}

packages/svelte/src/runtime/internal/public.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface ComponentConstructorOptions<
1414
}
1515

1616
/**
17-
* Convenience type to get the events the given component expects. Example:
17+
* Type utile pour obtenir les évènements qu'un composant attend. Exemple :
1818
* ```html
1919
* <script lang="ts">
2020
* import type { ComponentEvents } from 'svelte';
@@ -32,7 +32,7 @@ export type ComponentEvents<Component extends SvelteComponent> =
3232
Component extends SvelteComponentDev<any, infer Events> ? Events : never;
3333

3434
/**
35-
* Convenience type to get the props the given component expects. Example:
35+
* Type utile pour obtenir les <span class='vo'>[props](/docs/sveltejs#props)</span> qu'un composant attend. Exemple :
3636
* ```html
3737
* <script lang="ts">
3838
* import type { ComponentProps } from 'svelte';
@@ -46,10 +46,10 @@ export type ComponentProps<Component extends SvelteComponent> =
4646
Component extends SvelteComponentDev<infer Props> ? Props : never;
4747

4848
/**
49-
* Convenience type to get the type of a Svelte component. Useful for example in combination with
50-
* dynamic components using `<svelte:component>`.
49+
* Type utile pour obtenir le type d'un composant Svelte. Pratique par exemple lorsqu'on utilise les
50+
* composants dynamiques avec `<svelte:component>`.
5151
*
52-
* Example:
52+
* Exemple:
5353
* ```html
5454
* <script lang="ts">
5555
* import type { ComponentType, SvelteComponent } from 'svelte';
@@ -69,7 +69,7 @@ export type ComponentType<Component extends SvelteComponentDev = SvelteComponent
6969
Component extends SvelteComponentDev<infer Props> ? Props : Record<string, any>
7070
>
7171
) => Component) & {
72-
/** The custom element version of the component. Only present if compiled with the `customElement` compiler option */
72+
/** La version "web component" du composant. Seulement présent si compilé avec l'option `customElement` */
7373
element?: typeof HTMLElement;
7474
};
7575

0 commit comments

Comments
 (0)