Skip to content
This repository was archived by the owner on Nov 28, 2020. It is now read-only.

Commit e684ffd

Browse files
authored
Merge pull request #5 from kevinmarrec/migrate-to-new-specs
Migration to new default NUXT TS specs
2 parents bd14f27 + 01bceeb commit e684ffd

23 files changed

+10115
-10149
lines changed

common/api.js common/api.ts

File renamed without changes.

common/cache.js common/cache.ts

File renamed without changes.

components/comment.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</template>
2222

2323
<script lang="ts">
24-
import { Component, Prop, Vue } from "nuxt-property-decorator"
24+
import { Component, Prop, Vue } from "vue-property-decorator"
2525
2626
@Component({})
2727
export default class Comment extends Vue {

components/item-list-nav.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</template>
1010

1111
<script lang="ts">
12-
import { Component, Prop, Vue } from "nuxt-property-decorator"
12+
import { Component, Prop, Vue } from "vue-property-decorator"
1313
1414
@Component({})
1515
export default class ItemListNav extends Vue {

components/item.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</template>
2626

2727
<script lang="ts">
28-
import { Component, Prop, Vue } from "nuxt-property-decorator"
28+
import { Component, Prop, Vue } from "vue-property-decorator"
2929
3030
import { timeAgo } from "~/plugins/filters"
3131

components/spinner.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</template>
2323

2424
<script lang="ts">
25-
import { Component, Prop, Vue } from "nuxt-property-decorator"
25+
import { Component, Prop, Vue } from "vue-property-decorator"
2626
2727
@Component({})
2828
export default class Spinner extends Vue {

index.d.ts

-19
This file was deleted.

jsconfig.json

-6
This file was deleted.

layouts/default.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@
1919
</template>
2020

2121
<script lang="ts">
22-
import { Component, Vue } from "nuxt-property-decorator"
22+
import { Component, Vue } from "vue-property-decorator"
2323
2424
import { feeds } from "~/common/api"
2525
26-
@Component({})
27-
export default class Layout extends Vue {
26+
@Component({
2827
head() {
2928
// hack `(process as any)` to wait till this is fixed in Nuxt
30-
const host = (process as any).server
29+
const host = process.server
3130
? this.$ssrContext.req.headers.host
3231
: window.location.host
3332
@@ -38,7 +37,8 @@ export default class Layout extends Vue {
3837
]
3938
}
4039
}
41-
40+
})
41+
export default class Layout extends Vue {
4242
get feeds() {
4343
return feeds
4444
}

nuxt.config.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
const isDev = process.env.NODE_ENV !== "production"
2-
import consola from "consola"
32

43
export default {
54
mode: "spa",
65
modern: !isDev,
7-
build: { useForkTsChecker: { logger: consola } },
86
head: {
97
titleTemplate: "Nuxt HN TS | %s",
108
meta: [
@@ -53,7 +51,7 @@ export default {
5351
}
5452
},
5553
plugins: ["~/plugins/filters"],
56-
serverMiddleware: ["~/common/cache.js"],
54+
serverMiddleware: ["~/common/cache"],
5755
render: {
5856
http2: {
5957
push: true

package.json

+8-31
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,12 @@
1515
},
1616
{
1717
"name": "HG(@husayt)"
18+
},
19+
{
20+
"name": "Kevin Marrec (@kevinmarrec)"
1821
}
1922
],
2023
"private": true,
21-
"babel": {
22-
"env": {
23-
"test": {
24-
"presets": [
25-
[
26-
"@babel/preset-env",
27-
{
28-
"targets": {
29-
"node": "current"
30-
}
31-
}
32-
]
33-
]
34-
}
35-
}
36-
},
3724
"scripts": {
3825
"dev": "nuxt-ts dev",
3926
"build": "nuxt-ts build",
@@ -60,29 +47,20 @@
6047
"@nuxtjs/pwa": "2.6.0",
6148
"apicache": "1.2.3",
6249
"express": "4.16.4",
63-
"nuxt-property-decorator": "1.3.1",
50+
"vue-property-decorator": "^7.3.0",
6451
"nuxt-ts-edge": "latest"
6552
},
6653
"devDependencies": {
67-
"@babel/core": "^7.2.2",
68-
"@types/jest": "^23.3.10",
69-
"@types/node": "^10.12.12",
70-
"@vue/test-utils": "^1.0.0-beta.27",
71-
"babel-core": "^7.0.0-bridge.0",
72-
"babel-jest": "latest",
73-
"fork-ts-checker-webpack-plugin": "^0.5.2",
54+
"@types/jest": "^23.3.13",
55+
"@vue/test-utils": "^1.0.0-beta.28",
7456
"jest": "^23.6.0",
7557
"jest-serializer-vue": "^2.0.2",
76-
"lodash-es": "4.17.11",
77-
"prettier": "^1.15.3",
58+
"prettier": "^1.16.1",
7859
"stylus": "^0.54.5",
7960
"stylus-loader": "^3.0.2",
8061
"ts-jest": "^23.10.5",
81-
"ts-loader": "5.3.2",
82-
"tslint": "^5.12.0",
8362
"tslint-config-prettier": "^1.17.0",
8463
"tslint-plugin-prettier": "^2.0.1",
85-
"typescript": "^3.2.2",
8664
"vue-jest": "^3.0.2"
8765
},
8866
"jest": {
@@ -96,11 +74,10 @@
9674
"^@/(.*)$": "<rootDir>/$1"
9775
},
9876
"transform": {
99-
"^.+\\.js$": "babel-jest",
10077
".*\\.(vue)$": "vue-jest",
10178
"^.+\\.tsx?$": "ts-jest"
10279
},
103-
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
80+
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.ts$",
10481
"snapshotSerializers": [
10582
"jest-serializer-vue"
10683
]

pages/_feed/_page.vue

+19-22
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
</template>
1717

1818
<script lang="ts">
19-
import { Component, Watch, Vue } from "nuxt-property-decorator"
20-
import { Context, Transition, Route } from "index"
19+
import { Component, Watch, Vue } from "vue-property-decorator"
20+
import { Transition } from "@nuxt/vue-app-edge"
21+
import { Route } from "vue-router"
2122
2223
import Item from "~/components/item.vue"
2324
import ItemListNav from "~/components/item-list-nav.vue"
@@ -29,35 +30,31 @@ import { feeds, validFeeds } from "~/common/api"
2930
Item,
3031
ItemListNav,
3132
LazyWrapper
32-
}
33-
})
34-
export default class Page extends Vue {
35-
displayedPage: number = 1
36-
transition:
37-
| null
38-
| string
39-
| Transition
40-
| ((to: Route, from: Route) => string) = "slide-right"
41-
42-
async asyncData({ route }: Context) {
33+
},
34+
async asyncData({ route }) {
4335
return {
4436
displayedPage: Number(route.params.page) || 1
4537
}
46-
}
47-
48-
validate({ params: { feed } }: Context) {
38+
},
39+
validate({ params: { feed } }) {
4940
return validFeeds.includes(feed)
50-
}
51-
52-
fetch({ store, params: { feed, page = 1 } }: Context) {
41+
},
42+
fetch({ store, params: { feed, page = 1 } }) {
5343
return store.dispatch("FETCH_FEED", { feed, page })
54-
}
55-
56-
head() {
44+
},
45+
head(this: Page) {
5746
return {
5847
title: feeds[this.$route.params.feed].title
5948
}
6049
}
50+
})
51+
export default class Page extends Vue {
52+
displayedPage: number = 1
53+
transition:
54+
| null
55+
| string
56+
| Transition
57+
| ((to: Route, from: Route) => string) = "slide-right"
6158
6259
get feed() {
6360
return this.$route.params.feed

pages/index.tsx

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { Vue, Component } from "nuxt-property-decorator"
2-
import { Context } from "index.d.ts"
3-
import { validFeeds } from "~/common/api.js"
1+
import { Vue, Component } from "vue-property-decorator"
2+
import { validFeeds } from "~/common/api"
43

5-
@Component({})
6-
export default class Index extends Vue {
7-
fetch({ redirect }: Context) {
4+
@Component({
5+
fetch({ redirect }) {
86
redirect("/" + validFeeds[0])
97
}
10-
}
8+
})
9+
export default class Index extends Vue {}

pages/item/_id.vue

+8-11
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
</template>
3030

3131
<script lang="ts">
32-
import { Component, Vue } from "nuxt-property-decorator"
33-
import { Context } from "index"
32+
import { Component, Vue } from "vue-property-decorator"
3433
3534
import Comment from "~/components/comment.vue"
3635
import LazyWrapper from "~/components/lazy-wrapper.vue"
@@ -39,26 +38,24 @@ import LazyWrapper from "~/components/lazy-wrapper.vue"
3938
components: {
4039
Comment,
4140
LazyWrapper
42-
}
43-
})
44-
export default class ItemView extends Vue {
45-
head() {
41+
},
42+
head(this: ItemView) {
4643
return {
4744
title: this.item.title
4845
}
46+
},
47+
fetch({ store, params: { id } }) {
48+
return store.dispatch("FETCH_ITEM", { id })
4949
}
50-
50+
})
51+
export default class ItemView extends Vue {
5152
get id() {
5253
return this.$route.params.id
5354
}
5455
5556
get item() {
5657
return this.$store.state.items[this.id]
5758
}
58-
59-
fetch({ store, params: { id } }: Context) {
60-
return store.dispatch("FETCH_ITEM", { id })
61-
}
6259
}
6360
</script>
6461

pages/user/_id.vue

+10-13
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,29 @@
2828
</template>
2929

3030
<script lang="ts">
31-
import { Component, Vue } from "nuxt-property-decorator"
32-
import { Context } from "index"
31+
import { Component, Vue } from "vue-property-decorator"
3332
import LazyWrapper from "~/components/lazy-wrapper.vue"
3433
3534
@Component({
3635
components: {
3736
LazyWrapper
38-
}
39-
})
40-
export default class UserView extends Vue {
41-
get user() {
42-
return this.$store.state.users[this.$route.params.id]
43-
}
44-
45-
head() {
37+
},
38+
head(this: UserView) {
4639
return this.user ? this.user.id : "User not found"
47-
}
48-
40+
},
4941
fetch({
5042
store,
5143
route: {
5244
params: { id }
5345
}
54-
}: Context) {
46+
}) {
5547
return store.dispatch("FETCH_USER", { id })
5648
}
49+
})
50+
export default class UserView extends Vue {
51+
get user() {
52+
return this.$store.state.users[this.$route.params.id]
53+
}
5754
}
5855
</script>
5956

store/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Vue from "vue"
44

55
import { validFeeds } from "~/common/api"
66
import { lazy } from "~/common/utils"
7-
import { CancelToken } from "axios"
7+
// import { CancelToken } from "axios"
88
const baseUrl = "https://api.hnpwa.com/v0" // "/api"
99

1010
interface Dictionary<T> {
@@ -117,13 +117,13 @@ const actions: ActionTree<IRootState, any> = {
117117
prefetch = true
118118
}
119119
if (!prefetch) {
120-
if (this.feedCancelSource) {
120+
if ((this as any).feedCancelSource) {
121121
;(this as any).feedCancelSource.cancel(
122122
"prioritize feed: " + feed + " page: " + page
123123
)
124124
}
125125

126-
this.feedCancelSource = CancelToken.source()
126+
// ;(this as any).feedCancelSource = new CancelToken.source()
127127
}
128128

129129
return lazy(
@@ -135,7 +135,8 @@ const actions: ActionTree<IRootState, any> = {
135135
() =>
136136
(this as any).$axios.$get(`${baseUrl}/${feed}/${page}.json`, {
137137
cancelToken:
138-
this.feedCancelSource && (this as any).feedCancelSource.token
138+
(this as any).feedCancelSource &&
139+
(this as any).feedCancelSource.token
139140
}),
140141
(state.feeds[feed][page] || []).map(id => state.items[id])
141142
)

0 commit comments

Comments
 (0)