Skip to content

Commit feefe46

Browse files
authored
Merge pull request #194 from sveltejs/code-style
Code style
2 parents 50b7e1d + be01c6b commit feefe46

File tree

19 files changed

+214
-221
lines changed

19 files changed

+214
-221
lines changed

content/examples/7guis-circles/App.html

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,23 @@
6262

6363
<script>
6464
export default {
65-
data () {
65+
data() {
6666
return {
6767
i: 0,
68-
undoStack: [ [] ],
68+
undoStack: [[]],
6969
adjusting: false,
7070
adjusted: false,
7171
circles: []
7272
};
7373
},
7474

7575
methods: {
76-
handleClick ( event ) {
77-
if ( this.get( 'adjusting' ) ) {
76+
handleClick(event) {
77+
if (this.get('adjusting')) {
7878
this.set({ adjusting: false });
7979

8080
// if nothing changed, rewind
81-
if ( this.get( 'adjusted' ) ) this.push();
81+
if (this.get('adjusted')) this.push();
8282
return;
8383
}
8484

@@ -88,43 +88,43 @@
8888
r: 50
8989
};
9090

91-
const circles = this.get( 'circles' );
92-
circles.push( circle );
91+
const circles = this.get('circles');
92+
circles.push(circle);
9393
this.set({ circles, selected: circle });
9494

9595
this.push();
9696
},
9797

98-
adjust ( event ) {
98+
adjust(event) {
9999
event.preventDefault();
100-
if ( !this.get( 'selected' ) ) return;
100+
if (!this.get('selected')) return;
101101
this.set({ adjusting: true, adjusted: false });
102102
},
103103

104-
select ( circle, event ) {
105-
if ( !this.get( 'adjusting' ) ) {
104+
select(circle, event) {
105+
if (!this.get('adjusting')) {
106106
event.stopPropagation();
107107
this.set({ selected: circle });
108108
}
109109
},
110110

111111
// undo stack management
112-
push () {
112+
push() {
113113
let { i, undoStack, circles } = this.get();
114-
undoStack.splice( ++i );
115-
undoStack.push( clone( circles ) );
114+
undoStack.splice(++i);
115+
undoStack.push(clone(circles));
116116
this.set({ i, undoStack });
117117
},
118118

119-
travel ( d ) {
119+
travel(d) {
120120
let { i, undoStack } = this.get();
121-
const circles = clone( undoStack[ i += d ] );
121+
const circles = clone(undoStack[i += d]);
122122
this.set({ circles, i, adjusting: false });
123123
}
124124
}
125125
};
126126

127-
function clone ( circles ) {
128-
return circles.map( ({ cx, cy, r }) => ({ cx, cy, r }) );
127+
function clone(circles) {
128+
return circles.map(({ cx, cy, r }) => ({ cx, cy, r }));
129129
}
130130
</script>

content/examples/7guis-crud/App.html

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
<script>
4242
export default {
43-
data () {
43+
data() {
4444
return {
4545
prefix: '',
4646
first: '',
@@ -51,29 +51,29 @@
5151
},
5252

5353
computed: {
54-
selected: ( filteredPeople, i ) => {
54+
selected: (filteredPeople, i) => {
5555
return filteredPeople[i];
5656
},
5757

58-
filteredPeople ( people, prefix ) {
59-
if ( !prefix ) return people;
58+
filteredPeople(people, prefix) {
59+
if (!prefix) return people;
6060

6161
prefix = prefix.toLowerCase();
62-
return people.filter( person => {
62+
return people.filter(person => {
6363
const name = `${person.last}, ${person.first}`;
64-
return name.toLowerCase().startsWith( prefix );
64+
return name.toLowerCase().startsWith(prefix);
6565
});
6666
}
6767
},
6868

69-
oncreate () {
70-
this.observe( 'selected', selected => {
71-
if ( selected ) this.set( selected );
69+
oncreate() {
70+
this.observe('selected', selected => {
71+
if (selected) this.set(selected);
7272
});
7373
},
7474

7575
methods: {
76-
create () {
76+
create() {
7777
const { first, last, people } = this.get();
7878

7979
people.push({ first, last });
@@ -86,7 +86,7 @@
8686
});
8787
},
8888

89-
update () {
89+
update() {
9090
const { first, last, selected, people } = this.get();
9191

9292
selected.first = first;
@@ -95,16 +95,16 @@
9595
this.set({ people, selected });
9696
},
9797

98-
remove () {
98+
remove() {
9999
const { people, selected, i } = this.get();
100-
const index = people.indexOf( selected );
101-
people.splice( index, 1 );
100+
const index = people.indexOf(selected);
101+
people.splice(index, 1);
102102

103103
this.set({
104104
people,
105105
first: '',
106106
last: '',
107-
i: Math.min( i, people.length - 1 )
107+
i: Math.min(i, people.length - 1)
108108
});
109109
}
110110
}

content/examples/7guis-flight-booker/App.html

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222

2323
<script>
2424
export default {
25-
data () {
26-
const tomorrow = new Date( Date.now() + 86400000 );
25+
data() {
26+
const tomorrow = new Date(Date.now() + 86400000);
2727

2828
const tomorrowAsString = [
2929
tomorrow.getFullYear(),
30-
pad( tomorrow.getMonth() + 1, 2 ),
31-
pad( tomorrow.getDate(), 2 )
32-
].join( '-' );
30+
pad(tomorrow.getMonth() + 1, 2),
31+
pad(tomorrow.getDate(), 2)
32+
].join('-');
3333

3434
return {
3535
start: tomorrowAsString,
@@ -39,33 +39,33 @@
3939
},
4040

4141
computed: {
42-
startDate: start => convertToDate( start ),
43-
endDate: end => convertToDate( end )
42+
startDate: start => convertToDate(start),
43+
endDate: end => convertToDate(end)
4444
},
4545

4646
methods: {
47-
bookFlight () {
47+
bookFlight() {
4848
const { startDate, endDate, isReturn } = this.get();
4949
const type = isReturn ? 'return' : 'one-way';
5050

5151
let message = `You have booked a ${type} flight, leaving ${startDate.toDateString()}`;
52-
if ( type === 'return' ) {
52+
if (type === 'return') {
5353
message += ` and returning ${endDate.toDateString()}`;
5454
}
5555

56-
alert( message );
56+
alert(message);
5757
}
5858
}
5959
};
6060

61-
function convertToDate ( str ) {
62-
var split = str.split( '-' );
63-
return new Date( +split[0], +split[1] - 1, +split[2] );
61+
function convertToDate(str) {
62+
var split = str.split('-');
63+
return new Date(+split[0], +split[1] - 1, +split[2]);
6464
}
6565

66-
function pad ( x, len ) {
67-
x = String( x );
68-
while ( x.length < len ) x = `0${x}`;
66+
function pad(x, len) {
67+
x = String(x);
68+
while (x.length < len) x = `0${x}`;
6969
return x;
7070
}
7171
</script>

content/examples/7guis-temperature/App.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
<script>
1212
export default {
1313
oncreate: function () {
14-
this.observe( 'celsius', c => {
14+
this.observe('celsius', c => {
1515
this.set({
16-
fahrenheit: +( 32 + ( 9 / 5 * c ) ).toFixed( 1 )
16+
fahrenheit: +(32 + (9 / 5 * c)).toFixed(1)
1717
});
1818
});
1919

20-
this.observe( 'fahrenheit', f => {
20+
this.observe('fahrenheit', f => {
2121
this.set({
22-
celsius: +( 5 / 9 * ( f - 32 ) ).toFixed( 1 )
22+
celsius: +(5 / 9 * (f - 32)).toFixed(1)
2323
});
2424
});
2525
}

content/examples/7guis-timer/App.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,35 @@
1515

1616
<script>
1717
export default {
18-
data () {
18+
data() {
1919
return { elapsed: 0, duration: 5000 };
2020
},
2121

22-
oncreate () {
22+
oncreate() {
2323
this.reset();
2424

2525
const update = () => {
26-
this.frame = requestAnimationFrame( update );
26+
this.frame = requestAnimationFrame(update);
2727

2828
const { start, duration } = this.get();
2929
const elapsed = window.performance.now() - start;
3030

31-
if ( elapsed > duration ) return;
31+
if (elapsed > duration) return;
3232

3333
this.set({ elapsed });
3434
};
3535

3636
update();
3737
},
3838

39-
ondestroy () {
40-
if ( this.frame ) {
41-
cancelAnimationFrame( this.frame );
39+
ondestroy() {
40+
if (this.frame) {
41+
cancelAnimationFrame(this.frame);
4242
}
4343
},
4444

4545
methods: {
46-
reset () {
46+
reset() {
4747
this.set({
4848
start: window.performance.now()
4949
});

content/examples/area-chart/example.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

content/examples/bar-chart/App.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,37 +84,37 @@ <h2>US birthrate by year</h2>
8484
padding: { top: 20, right: 15, bottom: 20, left: 25 },
8585
height: 200,
8686
width: 500,
87-
xTicks: [ 1990, 1995, 2000, 2005, 2010, 2015 ],
88-
yTicks: [ 0, 5, 10, 15, 20 ]
87+
xTicks: [1990, 1995, 2000, 2005, 2010, 2015],
88+
yTicks: [0, 5, 10, 15, 20]
8989
};
9090
},
9191

9292
helpers: {
93-
formatMobile: function ( tick ) {
93+
formatMobile: function (tick) {
9494
return "'" + tick % 100;
9595
}
9696
},
9797

9898
computed: {
99-
barWidth: function ( xTicks, width, padding ) {
100-
var innerWidth = width - ( padding.left + padding.right );
99+
barWidth: function (xTicks, width, padding) {
100+
var innerWidth = width - (padding.left + padding.right);
101101
return innerWidth / xTicks.length;
102102
},
103103

104-
xScale: function ( padding, width, xTicks ) {
104+
xScale: function (padding, width, xTicks) {
105105
return xScale
106106
.domain([0, xTicks.length])
107107
.range([padding.left, width - padding.right]);
108108
},
109109

110-
yScale: function ( padding, height, yTicks ) {
110+
yScale: function (padding, height, yTicks) {
111111
return yScale
112112
.domain([0, Math.max.apply(null, yTicks)])
113113
.range([height - padding.bottom, padding.top]);
114114
}
115115
},
116116

117-
oncreate () {
117+
oncreate() {
118118
this.resize();
119119
},
120120

0 commit comments

Comments
 (0)