Skip to content

Commit 9628634

Browse files
MachinisteWebchrisvfritz
authored andcommitted
[Doc EN]: Remove trailing + correct return line + Vue Convention implementation into cookbook (#1711)
* New in with + symbol Signed-off-by: Bruno Lesieur <[email protected]> * Review of 2.5.0 doc Signed-off-by: Bruno Lesieur <[email protected]> * Review Signed-off-by: Bruno Lesieur <[email protected]> * Fix syntax typo Signed-off-by: Bruno Lesieur <[email protected]> * Add space between new line of documentation Signed-off-by: MachinisteWeb <[email protected]> * Add @posva review Signed-off-by: MachinisteWeb <[email protected]> * Add french str Signed-off-by: MachinisteWeb <[email protected]> * Change directeur to director Signed-off-by: MachinisteWeb <[email protected]> * Fix EN doc Signed-off-by: MachinisteWeb <[email protected]> * Subtitle for typescript.md Signed-off-by: MachinisteWeb <[email protected]> * Revert instance.md Signed-off-by: MachinisteWeb <[email protected]> * Remove trailing + Convention Vue implementation into Cookbook Signed-off-by: MachinisteWeb <[email protected]> * space into bracket Signed-off-by: MachinisteWeb <[email protected]> * Add tag line return Signed-off-by: MachinisteWeb <[email protected]>
1 parent 98a3946 commit 9628634

8 files changed

+230
-87
lines changed

src/v2/cookbook/avoiding-memory-leaks.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: Avoiding Memory Leaks
33
type: cookbook
44
order: 10
55
---
6+
67
## Introduction
78

89
If you are developing applications with Vue, then you need to watch out for memory leaks. This issue is especially important in Single Page Applications (SPAs) because by design, users should not have to refresh their browser when using an SPA, so it is up to the JavaScript application to clean up components and make sure that garbage collection takes place as expected.
@@ -13,20 +14,27 @@ Memory leaks in Vue applications do not typically come from Vue itself, rather t
1314

1415
The following example shows a memory leak caused by using the [Choices.js](https://github.com/jshjohnson/Choices) library in a Vue component and not properly cleaning it up. Later, we will show how to remove the Choices.js footprint and avoid the memory leak.
1516

16-
In the example below, we load up a select with a lot of options and then we use a show/hide button with a [v-if](/v2/guide/conditional.html) directive to add it and remove it from the virtual DOM. The problem with this example is that the `v-if` directive removes the parent element from the DOM, but we did not clean up the additional DOM pieces created by Choices.js, causing a memory leak.
17+
In the example below, we load up a select with a lot of options and then we use a show/hide button with a [v-if](/v2/guide/conditional.html) directive to add it and remove it from the virtual DOM. The problem with this example is that the `v-if` directive removes the parent element from the DOM, but we did not clean up the additional DOM pieces created by Choices.js, causing a memory leak.
1718

1819
```html
1920
<link rel='stylesheet prefetch' href='https://joshuajohnson.co.uk/Choices/assets/styles/css/choices.min.css?version=3.0.3'>
2021
<script src='https://joshuajohnson.co.uk/Choices/assets/scripts/dist/choices.min.js?version=3.0.3'></script>
2122

2223
<div id="app">
23-
<button v-if="showChoices" @click="hide">Hide</button>
24-
<button v-if="!showChoices" @click="show">Show</button>
24+
<button
25+
v-if="showChoices"
26+
@click="hide"
27+
>Hide</button>
28+
<button
29+
v-if="!showChoices"
30+
@click="show"
31+
>Show</button>
2532
<div v-if="showChoices">
2633
<select id="choices-single-default"></select>
2734
</div>
2835
</div>
2936
```
37+
3038
```js
3139
new Vue({
3240
el: "#app",
@@ -41,7 +49,7 @@ new Vue({
4149
methods: {
4250
initializeChoices: function () {
4351
let list = []
44-
// lets load up our select with many choices
52+
// lets load up our select with many choices
4553
// so it will use a lot of memory
4654
for (let i = 0; i < 1000; i++) {
4755
list.push({
@@ -67,6 +75,7 @@ new Vue({
6775
}
6876
})
6977
```
78+
7079
To see this memory leak in action, open this [CodePen example](https://codepen.io/freeman-g/pen/qobpxo) using Chrome and then open the Chrome Task Manager. To open the Chrome Task Manager on Mac, choose Chrome Top Navigation > Window > Task Manager or on Windows, use the Shift+Esc shortcut. Now, click the show/hide button 50 or so times. You should see the memory usage in the Chrome Task Manager increase and never be reclaimed.
7180

7281
![Memory Leak Example](/images/memory-leak-example.png)
@@ -112,7 +121,7 @@ new Vue({
112121
})
113122
},
114123
hide: function () {
115-
// now we can use the reference to Choices to perform clean up here
124+
// now we can use the reference to Choices to perform clean up here
116125
// prior to removing the elements from the DOM
117126
this.choicesSelect.destroy()
118127
this.showChoices = false
@@ -123,7 +132,7 @@ new Vue({
123132

124133
## Details about the Value
125134

126-
Memory management and performance testing can easily be neglected in the excitement of shipping quickly, however, keeping a small memory footprint is still important to your overall user experience.
135+
Memory management and performance testing can easily be neglected in the excitement of shipping quickly, however, keeping a small memory footprint is still important to your overall user experience.
127136

128137
Consider the types of devices your users may be using and what their normal flow will be. Could they use memory constrained laptops or mobile devices? Do your users typically do lots of in-application navigation? If either of these are true, then good memory management practices can help you avoid the worst case scenario of crashing a user’s browser. Even if neither of these are true, you can still potentially have degradation of performance over extended usage of your app if you are not careful.
129138

src/v2/cookbook/client-side-storage.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ order: 11
66

77
## Base Example
88

9-
Client-side storage is an excellent way to quickly add performance gains to an application. By storing data on the browser itself, you can skip fetching information from the server every time the user needs it. While especially useful when offline, even online users will benefit from using data locally versus a remote server. Client-side storage can be done with [cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies), [Local Storage](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API) (technically "Web Storage"), [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API), and [WebSQL](https://www.w3.org/TR/webdatabase/) (a deprecated method that should not be used in new projects).
9+
Client-side storage is an excellent way to quickly add performance gains to an application. By storing data on the browser itself, you can skip fetching information from the server every time the user needs it. While especially useful when offline, even online users will benefit from using data locally versus a remote server. Client-side storage can be done with [cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies), [Local Storage](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API) (technically "Web Storage"), [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API), and [WebSQL](https://www.w3.org/TR/webdatabase/) (a deprecated method that should not be used in new projects).
1010

11-
In this cookbook entry we'll focus on Local Storage, the simplest of the storage mechanisms. Local Storage uses a key/value system for storing data. It is limited to storing only simple values but complex data can be stored if you are willing to encode and decode the values with JSON. In general, Local Storage is appropriate for smaller sets of data you would want to persist, things like user preferences or form data. Larger data with more complex storage needs would be better stored typically in IndexedDB.
11+
In this cookbook entry we'll focus on Local Storage, the simplest of the storage mechanisms. Local Storage uses a key/value system for storing data. It is limited to storing only simple values but complex data can be stored if you are willing to encode and decode the values with JSON. In general, Local Storage is appropriate for smaller sets of data you would want to persist, things like user preferences or form data. Larger data with more complex storage needs would be better stored typically in IndexedDB.
1212

1313
Let's begin with a simple form based example:
1414

@@ -39,7 +39,7 @@ const app = new Vue({
3939
});
4040
```
4141

42-
Focus on the `mounted` and `watch` parts. We use `mounted` to handle loading the value from localStorage. To handle writing the data base, we watch the `name` value and on change, immediately write it.
42+
Focus on the `mounted` and `watch` parts. We use `mounted` to handle loading the value from localStorage. To handle writing the data base, we watch the `name` value and on change, immediately write it.
4343

4444
You can run this yourself here:
4545

@@ -64,16 +64,19 @@ Immediately writing the value may not advisable. Let's consider a slightly more
6464

6565
``` html
6666
<div id="app">
67-
My name is <input v-model="name">
68-
and I am <input v-model="age"> years old.
69-
<p/>
70-
<button @click="persist">Save</button>
67+
<p>
68+
My name is <input v-model="name">
69+
and I am <input v-model="age"> years old.
70+
</p>
71+
<p>
72+
<button @click="persist">Save</button>
73+
</p>
7174
</div>
7275
```
7376

7477
Now we've got two fields (again, bound to a Vue instance) but now there is the addition of a button that runs a `persist` method. Let's look at the JavaScript.
7578

76-
``` js
79+
``` js
7780
const app = new Vue({
7881
el:'#app',
7982
data: {
@@ -105,22 +108,22 @@ As before, `mounted` is used to load persisted data, if it exists. This time, th
105108

106109
## Working with Complex Values
107110

108-
As mentioned above, Local Storage only works with simple values. To store more complex values, like objects or arrays, you must serialize and deserialize the values with JSON. Here is a more advanced example that persists an array of cats (the best kind of array possible).
111+
As mentioned above, Local Storage only works with simple values. To store more complex values, like objects or arrays, you must serialize and deserialize the values with JSON. Here is a more advanced example that persists an array of cats (the best kind of array possible).
109112

110113
``` html
111114
<div id="app">
112115
<h2>Cats</h2>
113-
<div v-for="(cat,n) in cats">
116+
<div v-for="(cat, n) in cats">
114117
<p>
115-
<span class="cat">{{ cat }}</span> <button @click="removeCat(n)">Remove</button>
118+
<span class="cat">{{ cat }}</span>
119+
<button @click="removeCat(n)">Remove</button>
116120
</p>
117121
</div>
118-
122+
119123
<p>
120-
<input v-model="newCat">
124+
<input v-model="newCat">
121125
<button @click="addCat">Add Cat</button>
122126
</p>
123-
124127
</div>
125128
```
126129

@@ -134,7 +137,6 @@ const app = new Vue({
134137
newCat: null
135138
},
136139
mounted() {
137-
138140
if (localStorage.getItem('cats')) {
139141
try {
140142
this.cats = JSON.parse(localStorage.getItem('cats'));
@@ -149,7 +151,7 @@ const app = new Vue({
149151
if (!this.newCat) {
150152
return;
151153
}
152-
154+
153155
this.cats.push(this.newCat);
154156
this.newCat = '';
155157
this.saveCats();

src/v2/cookbook/creating-custom-scroll-directives.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ new Vue({
4040
```html
4141
<div id="app">
4242
<h1 class="centered">Scroll me</h1>
43-
<div class="box" v-scroll="handleScroll">
43+
<div
44+
v-scroll="handleScroll"
45+
class="box"
46+
>
4447
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A atque amet harum aut ab veritatis earum porro praesentium ut corporis. Quasi provident dolorem officia iure fugiat, eius mollitia sequi quisquam.</p>
4548
</div>
4649
</div>

src/v2/cookbook/dockerize-vuejs-app.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Let's see how these concepts actually affect our decision of dockerizing our Vue
109109

110110
### Effects of Microservices
111111

112-
By adopting the [microservices architectural style](https://martinfowler.com/microservices/), we end up building a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms. These services are built around business capabilities and independently deployable by fully automated deployment machinery.
112+
By adopting the [microservices architectural style](https://martinfowler.com/microservices/), we end up building a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms. These services are built around business capabilities and independently deployable by fully automated deployment machinery.
113113

114114
So, committing to this architectural approach most of the time implies developing and delivering our front-end as an independent service.
115115

src/v2/cookbook/editable-svg-icons.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ We'll create a base icon (`IconBase.vue`) component that uses a slot.
3535
:aria-labelledby="iconName"
3636
role="presentation"
3737
>
38-
<title :id="iconName" lang="en">{{iconName}} icon</title>
38+
<title
39+
:id="iconName"
40+
lang="en"
41+
>{{ iconName }} icon</title>
3942
<g :fill="iconColor">
4043
<slot />
4144
</g>
@@ -83,11 +86,19 @@ Now, if we'd like to make many sizes for the icon, we can do so very easily:
8386
```html
8487
<p>
8588
<!-- you can pass in a smaller `width` and `height` as props -->
86-
<icon-base width="12" height="12" icon-name="write"><icon-write /></icon-base>
89+
<icon-base
90+
width="12"
91+
height="12"
92+
icon-name="write"
93+
><icon-write /></icon-base>
8794
<!-- or you can use the default, which is 18 -->
8895
<icon-base icon-name="write"><icon-write /></icon-base>
8996
<!-- or make it a little bigger too :) -->
90-
<icon-base width="30" height="30" icon-name="write"><icon-write /></icon-base>
97+
<icon-base
98+
width="30"
99+
height="30"
100+
icon-name="write"
101+
><icon-write /></icon-base>
91102
</p>
92103
```
93104

@@ -99,16 +110,23 @@ Keeping icons in components comes in very handy when you'd like to animate them,
99110

100111
```html
101112
<template>
102-
<svg @click="startScissors"
113+
<svg
114+
@click="startScissors"
103115
xmlns="http://www.w3.org/2000/svg"
104116
viewBox="0 0 100 100"
105117
width="100"
106118
height="100"
107119
aria-labelledby="scissors"
108120
role="presentation"
109-
>
110-
<title id="scissors" lang="en">Scissors Animated Icon</title>
111-
<path id="bk" fill="#fff" d="M0 0h100v100H0z"/>
121+
>
122+
<title
123+
id="scissors"
124+
lang="en"
125+
>Scissors Animated Icon</title>
126+
<path
127+
id="bk"
128+
fill="#fff"
129+
d="M0 0h100v100H0z"/>
112130
<g ref="leftscissor">
113131
<path d="M..."/>
114132
...

0 commit comments

Comments
 (0)