Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traduction getters.md #9

Merged
merged 7 commits into from
May 20, 2017
Merged

Traduction getters.md #9

merged 7 commits into from
May 20, 2017

Conversation

MachinisteWeb
Copy link
Member

On continue avec les accesseurs !

Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com>
@MachinisteWeb MachinisteWeb self-assigned this May 20, 2017
Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com>
Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com>
Copy link
Member

@Kocal Kocal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh bien, tu es chaud ce matin ^^

Pas grand chose à review par contre.


Vuex allows us to define "getters" in the store (think of them as computed properties for stores). Getters will receive the state as their 1st argument:
Vuex nous permet de définir des "getters" dans le store (voyez-les comme les computed properties des store). Les getters prennent le state en premier argument :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

des stores

Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com>
Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com>
Copy link
Member Author

@MachinisteWeb MachinisteWeb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mes retours sur getters.md


Sometimes we may need to compute derived state based on store state, for example filtering through a list of items and counting them:
Parfois nous avons besoin de calculer des valeurs basées sur le state du store, par exemple pour filtrer une liste d'éléments et les compter :
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l'état

@@ -10,9 +10,9 @@ computed: {
}
```

If more than one component needs to make use of this, we have to either duplicate the function, or extract it into a shared helper and import it in multiple places - both are less than ideal.
Si plus d'un composant a besoin d'utiliser cela, il nous faut ou bien dupliquer cette fonction, ou bien l'extraire dans un helper séparé et l'importer aux endroits nécessaires &mdash; les deux idées sont loin d'être idéales.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l'extraire dans une fonction utilitaire séparée

nécessaires. Les deux


Vuex allows us to define "getters" in the store (think of them as computed properties for stores). Getters will receive the state as their 1st argument:
Vuex nous permet de définir des "getters" dans le store (voyez-les comme les computed properties des store). Les getters prennent le state en premier argument :
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

des accesseurs (« getters »)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

voyez-les comme les propriétés calculées des stores

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Les accesseurs prennent l'état

@@ -30,13 +30,13 @@ const store = new Vuex.Store({
})
```

The getters will be exposed on the `store.getters` object:
Les getters seront exposé sur l'objet `store.getters` :
Copy link
Member Author

@MachinisteWeb MachinisteWeb May 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Les accesseurs seront exposés


``` js
store.getters.doneTodos // -> [{ id: 1, text: '...', done: true }]
```

Getters will also receive other getters as the 2nd argument:
Les getters recevront également les autres getters en second argument :
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Les accesseurs
les autres accesseurs

@@ -75,18 +76,17 @@ getters: {
store.getters.getTodoById(2) // -> { id: 2, text: '...', done: false }
```

### Le helper `mapGetters`
Copy link
Member Author

@MachinisteWeb MachinisteWeb May 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La fonction utilitaire mapGetters

### The `mapGetters` Helper

The `mapGetters` helper simply maps store getters to local computed properties:
Le helper `mapGetters` attache simplement vos getters du store aux computed properties locales :
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L'utilitaire mapGetters

vos accesseurs du store

propriétés calculées locales


``` js
import { mapGetters } from 'vuex'

export default {
// ...
computed: {
// mix the getters into computed with object spread operator
// rajouter les getters dans computed avec l'object spread operator
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

les accesseurs dans computed avec l'opérateur de décomposition

@@ -96,11 +96,11 @@ export default {
}
```

If you want to map a getter to a different name, use an object:
Si vous voulez attacher un getter avec un nom différent, utilisez un objet :
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

un accesseur

...mapGetters({
// map this.doneCount to store.getters.doneTodosCount
mapGetters({
// attacher this.doneCount à store.getters.doneTodosCount
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.doneCount à store.getters.doneTodosCount

Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com>
Signed-off-by: Bruno Lesieur <bruno.lesieur@gmail.com>
@MachinisteWeb MachinisteWeb merged commit 5283090 into working May 20, 2017
@MachinisteWeb MachinisteWeb deleted the getters branch May 20, 2017 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants