Skip to content

Commit 3e4a1ec

Browse files
author
chibing.fy
committed
prettier
1 parent 98399b5 commit 3e4a1ec

22 files changed

+264
-200
lines changed

src/App.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
<header class="header">
44
<nav class="inner">
55
<router-link to="/" exact>
6-
<img class="logo" src="~public/logo-48.png" alt="logo">
6+
<img class="logo" src="~public/logo-48.png" alt="logo" />
77
</router-link>
88
<router-link to="/top">Top</router-link>
99
<router-link to="/new">New</router-link>
1010
<router-link to="/show">Show</router-link>
1111
<router-link to="/ask">Ask</router-link>
1212
<router-link to="/job">Jobs</router-link>
13-
<a class="github" href="https://github.com/vuejs/vue-hackernews-2.0" target="_blank" rel="noopener">
13+
<a
14+
class="github"
15+
href="https://github.com/vuejs/vue-hackernews-2.0"
16+
target="_blank"
17+
rel="noopener"
18+
>
1419
Built with Vue.js
1520
</a>
1621
</nav>

src/api/create-api-client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Firebase from 'firebase/app'
22
import 'firebase/database'
33

4-
export function createAPI ({ config, version }) {
4+
export function createAPI({ config, version }) {
55
Firebase.initializeApp(config)
66
return Firebase.database().ref(version)
77
}

src/api/create-api-server.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Firebase from 'firebase'
22
import LRU from 'lru-cache'
33

4-
export function createAPI ({ config, version }) {
4+
export function createAPI({ config, version }) {
55
let api
66
// this piece of code may run multiple times in development mode,
77
// so we attach the instantiated API to `process` to avoid duplications
@@ -16,13 +16,13 @@ export function createAPI ({ config, version }) {
1616
// fetched item cache
1717
api.cachedItems = LRU({
1818
max: 1000,
19-
maxAge: 1000 * 60 * 15 // 15 min cache
19+
maxAge: 1000 * 60 * 15, // 15 min cache
2020
})
2121

2222
// cache the latest story ids
2323
api.cachedIds = {}
24-
;['top', 'new', 'show', 'ask', 'job'].forEach(type => {
25-
api.child(`${type}stories`).on('value', snapshot => {
24+
;['top', 'new', 'show', 'ask', 'job'].forEach((type) => {
25+
api.child(`${type}stories`).on('value', (snapshot) => {
2626
api.cachedIds[type] = snapshot.val()
2727
})
2828
})

src/api/index.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const logRequests = !!process.env.DEBUG_API
66
const api = createAPI({
77
version: '/v0',
88
config: {
9-
databaseURL: 'https://hacker-news.firebaseio.com'
10-
}
9+
databaseURL: 'https://hacker-news.firebaseio.com',
10+
},
1111
})
1212

1313
// warm the front page cache every 15 min
@@ -16,53 +16,57 @@ if (api.onServer) {
1616
warmCache()
1717
}
1818

19-
function warmCache () {
19+
function warmCache() {
2020
fetchItems((api.cachedIds.top || []).slice(0, 30))
2121
setTimeout(warmCache, 1000 * 60 * 15)
2222
}
2323

24-
function fetch (child) {
24+
function fetch(child) {
2525
logRequests && console.log(`fetching ${child}...`)
2626
const cache = api.cachedItems
2727
if (cache && cache.has(child)) {
2828
logRequests && console.log(`cache hit for ${child}.`)
2929
return Promise.resolve(cache.get(child))
3030
} else {
3131
return new Promise((resolve, reject) => {
32-
api.child(child).once('value', snapshot => {
33-
const val = snapshot.val()
34-
// mark the timestamp when this item is cached
35-
if (val) val.__lastUpdated = Date.now()
36-
cache && cache.set(child, val)
37-
logRequests && console.log(`fetched ${child}.`)
38-
resolve(val)
39-
}, reject)
32+
api.child(child).once(
33+
'value',
34+
(snapshot) => {
35+
const val = snapshot.val()
36+
// mark the timestamp when this item is cached
37+
if (val) val.__lastUpdated = Date.now()
38+
cache && cache.set(child, val)
39+
logRequests && console.log(`fetched ${child}.`)
40+
resolve(val)
41+
},
42+
reject
43+
)
4044
})
4145
}
4246
}
4347

44-
export function fetchIdsByType (type) {
48+
export function fetchIdsByType(type) {
4549
return api.cachedIds && api.cachedIds[type]
4650
? Promise.resolve(api.cachedIds[type])
4751
: fetch(`${type}stories`)
4852
}
4953

50-
export function fetchItem (id) {
54+
export function fetchItem(id) {
5155
return fetch(`item/${id}`)
5256
}
5357

54-
export function fetchItems (ids) {
55-
return Promise.all(ids.map(id => fetchItem(id)))
58+
export function fetchItems(ids) {
59+
return Promise.all(ids.map((id) => fetchItem(id)))
5660
}
5761

58-
export function fetchUser (id) {
62+
export function fetchUser(id) {
5963
return fetch(`user/${id}`)
6064
}
6165

62-
export function watchList (type, cb) {
66+
export function watchList(type, cb) {
6367
let first = true
6468
const ref = api.child(`${type}stories`)
65-
const handler = snapshot => {
69+
const handler = (snapshot) => {
6670
if (first) {
6771
first = false
6872
} else {

src/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import * as filters from './util/filters'
1010
Vue.mixin(titleMixin)
1111

1212
// register global utility filters.
13-
Object.keys(filters).forEach(key => {
13+
Object.keys(filters).forEach((key) => {
1414
Vue.filter(key, filters[key])
1515
})
1616

1717
// Expose a factory function that creates a fresh set of store, router,
1818
// app instances on each call (which is called for each SSR request)
19-
export function createApp () {
19+
export function createApp() {
2020
// create store and router instances
2121
const store = createStore()
2222
const router = createRouter()
@@ -31,7 +31,7 @@ export function createApp () {
3131
const app = new Vue({
3232
router,
3333
store,
34-
render: h => h(App)
34+
render: (h) => h(App),
3535
})
3636

3737
// expose the app, the router and the store.

src/components/Comment.vue

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
{{ comment.time | timeAgo }} ago
66
</div>
77
<div class="text" v-html="comment.text"></div>
8-
<div class="toggle" :class="{ open }" v-if="comment.kids && comment.kids.length">
8+
<div
9+
class="toggle"
10+
:class="{ open }"
11+
v-if="comment.kids && comment.kids.length"
12+
>
913
<a @click="open = !open">{{
10-
open
11-
? '[-]'
12-
: '[+] ' + pluralize(comment.kids.length) + ' collapsed'
14+
open ? '[-]' : '[+] ' + pluralize(comment.kids.length) + ' collapsed'
1315
}}</a>
1416
</div>
1517
<ul class="comment-children" v-show="open">
@@ -22,19 +24,19 @@
2224
export default {
2325
name: 'comment',
2426
props: ['id'],
25-
data () {
27+
data() {
2628
return {
27-
open: true
29+
open: true,
2830
}
2931
},
3032
computed: {
31-
comment () {
33+
comment() {
3234
return this.$store.state.items[this.id]
33-
}
35+
},
3436
},
3537
methods: {
36-
pluralize: n => n + (n === 1 ? ' reply' : ' replies')
37-
}
38+
pluralize: (n) => n + (n === 1 ? ' reply' : ' replies'),
39+
},
3840
}
3941
</script>
4042

src/components/Item.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
<router-link :to="'/item/' + item.id">{{ item.title }}</router-link>
1111
</template>
1212
</span>
13-
<br>
13+
<br />
1414
<span class="meta">
1515
<span v-if="item.type !== 'job'" class="by">
1616
by <router-link :to="'/user/' + item.by">{{ item.by }}</router-link>
1717
</span>
18-
<span class="time">
19-
{{ item.time | timeAgo }} ago
20-
</span>
18+
<span class="time"> {{ item.time | timeAgo }} ago </span>
2119
<span v-if="item.type !== 'job'" class="comments-link">
22-
| <router-link :to="'/item/' + item.id">{{ item.descendants }} comments</router-link>
20+
|
21+
<router-link :to="'/item/' + item.id"
22+
>{{ item.descendants }} comments</router-link
23+
>
2324
</span>
2425
</span>
2526
<span class="label" v-if="item.type !== 'story'">{{ item.type }}</span>
@@ -33,9 +34,9 @@ export default {
3334
name: 'news-item',
3435
props: ['item'],
3536
// http://ssr.vuejs.org/en/caching.html#component-level-caching
36-
serverCacheKey: ({ item: { id, __lastUpdated, time }}) => {
37+
serverCacheKey: ({ item: { id, __lastUpdated, time } }) => {
3738
return `${id}::${__lastUpdated}::${timeAgo(time)}`
38-
}
39+
},
3940
}
4041
</script>
4142

src/components/ProgressBar.vue

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
<!-- borrowed from Nuxt! -->
22

33
<template>
4-
<div class="progress" :style="{
5-
'width': percent+'%',
6-
'height': height,
7-
'background-color': canSuccess? color : failedColor,
8-
'opacity': show ? 1 : 0
9-
}"></div>
4+
<div
5+
class="progress"
6+
:style="{
7+
width: percent + '%',
8+
height: height,
9+
'background-color': canSuccess ? color : failedColor,
10+
opacity: show ? 1 : 0,
11+
}"
12+
></div>
1013
</template>
1114

1215
<script>
1316
export default {
14-
data () {
17+
data() {
1518
return {
1619
percent: 0,
1720
show: false,
@@ -23,7 +26,7 @@ export default {
2326
}
2427
},
2528
methods: {
26-
start () {
29+
start() {
2730
this.show = true
2831
this.canSuccess = true
2932
if (this._timer) {
@@ -39,33 +42,33 @@ export default {
3942
}, 100)
4043
return this
4144
},
42-
set (num) {
45+
set(num) {
4346
this.show = true
4447
this.canSuccess = true
4548
this.percent = Math.floor(num)
4649
return this
4750
},
48-
get () {
51+
get() {
4952
return Math.floor(this.percent)
5053
},
51-
increase (num) {
54+
increase(num) {
5255
this.percent = this.percent + Math.floor(num)
5356
return this
5457
},
55-
decrease (num) {
58+
decrease(num) {
5659
this.percent = this.percent - Math.floor(num)
5760
return this
5861
},
59-
finish () {
62+
finish() {
6063
this.percent = 100
6164
this.hide()
6265
return this
6366
},
64-
pause () {
67+
pause() {
6568
clearInterval(this._timer)
6669
return this
6770
},
68-
hide () {
71+
hide() {
6972
clearInterval(this._timer)
7073
this._timer = null
7174
setTimeout(() => {
@@ -78,11 +81,11 @@ export default {
7881
}, 500)
7982
return this
8083
},
81-
fail () {
84+
fail() {
8285
this.canSuccess = false
8386
return this
84-
}
85-
}
87+
},
88+
},
8689
}
8790
</script>
8891

src/components/Spinner.vue

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
<template>
22
<transition>
3-
<svg class="spinner" :class="{ show: show }" v-show="show" width="44px" height="44px" viewBox="0 0 44 44">
4-
<circle class="path" fill="none" stroke-width="4" stroke-linecap="round" cx="22" cy="22" r="20"></circle>
3+
<svg
4+
class="spinner"
5+
:class="{ show: show }"
6+
v-show="show"
7+
width="44px"
8+
height="44px"
9+
viewBox="0 0 44 44"
10+
>
11+
<circle
12+
class="path"
13+
fill="none"
14+
stroke-width="4"
15+
stroke-linecap="round"
16+
cx="22"
17+
cy="22"
18+
r="20"
19+
></circle>
520
</svg>
621
</transition>
722
</template>
@@ -10,7 +25,7 @@
1025
export default {
1126
name: 'spinner',
1227
props: ['show'],
13-
serverCacheKey: props => props.show
28+
serverCacheKey: (props) => props.show,
1429
}
1530
</script>
1631

0 commit comments

Comments
 (0)