Skip to content

Commit f364a4d

Browse files
authored
Merge pull request #15 from guillaumebriday/feature/remove-else
Removing useless else statements
2 parents b036762 + 54b48c4 commit f364a4d

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

src/fetch_request.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ export class FetchRequest {
1919
console.error(error)
2020
}
2121
const response = new FetchResponse(await window.fetch(this.url, this.fetchOptions))
22+
2223
if (response.unauthenticated && response.authenticationURL) {
2324
return Promise.reject(window.location.href = response.authenticationURL)
24-
} else {
25-
if (response.ok && response.isTurboStream) { response.renderTurboStream() }
26-
return response
2725
}
26+
27+
if (response.ok && response.isTurboStream) { response.renderTurboStream() }
28+
return response
2829
}
2930

3031
addHeader (key, value) {
@@ -67,9 +68,9 @@ export class FetchRequest {
6768
return undefined
6869
} else if (this.body instanceof window.File) {
6970
return this.body.type
70-
} else {
71-
return 'application/json'
7271
}
72+
73+
return 'application/json'
7374
}
7475

7576
get accept () {
@@ -104,12 +105,14 @@ export class FetchRequest {
104105

105106
function compact (object) {
106107
const result = {}
108+
107109
for (const key in object) {
108110
const value = object[key]
109111
if (value !== undefined) {
110112
result[key] = value
111113
}
112114
}
115+
113116
return result
114117
}
115118

src/fetch_response.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class FetchResponse {
2121

2222
get contentType () {
2323
const contentType = this.response.headers.get('Content-Type') || ''
24+
2425
return contentType.replace(/;.*$/, '')
2526
}
2627

@@ -31,17 +32,17 @@ export class FetchResponse {
3132
get html () {
3233
if (this.contentType.match(/^(application|text)\/(html|xhtml\+xml)$/)) {
3334
return this.response.text()
34-
} else {
35-
return Promise.reject(new Error(`Expected an HTML response but got "${this.contentType}" instead`))
3635
}
36+
37+
return Promise.reject(new Error(`Expected an HTML response but got "${this.contentType}" instead`))
3738
}
3839

3940
get json () {
4041
if (this.contentType.match(/^application\/json/)) {
4142
return this.response.json()
42-
} else {
43-
return Promise.reject(new Error(`Expected a JSON response but got "${this.contentType}" instead`))
4443
}
44+
45+
return Promise.reject(new Error(`Expected a JSON response but got "${this.contentType}" instead`))
4546
}
4647

4748
get text () {
@@ -59,8 +60,8 @@ export class FetchResponse {
5960
} else {
6061
console.warn('You must set `window.Turbo = Turbo` to automatically process Turbo Stream events with request.js')
6162
}
62-
} else {
63-
return Promise.reject(new Error(`Expected a Turbo Stream response but got "${this.contentType}" instead`))
6463
}
64+
65+
return Promise.reject(new Error(`Expected a Turbo Stream response but got "${this.contentType}" instead`))
6566
}
6667
}

src/lib/cookie.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export function getCookie (name) {
55

66
if (cookie) {
77
const value = cookie.split('=').slice(1).join('=')
8-
return value ? decodeURIComponent(value) : undefined
8+
9+
if (value) {
10+
return decodeURIComponent(value)
11+
}
912
}
1013
}

0 commit comments

Comments
 (0)