diff options
author | Vijay A <avijayr@protonmail.com> | 2021-09-04 22:10:28 +0530 |
---|---|---|
committer | Vijay A <avijayr@protonmail.com> | 2021-09-05 05:01:51 +0530 |
commit | 92627555c6b0d56c96a95e31780e3015b3e637e9 (patch) | |
tree | 314beb586594c964dc5dbbb77bc47183ba273dd7 | |
parent | chore: auto-generated files [skip ci] (diff) | |
download | ferdium-app-92627555c6b0d56c96a95e31780e3015b3e637e9.tar.gz ferdium-app-92627555c6b0d56c96a95e31780e3015b3e637e9.tar.zst ferdium-app-92627555c6b0d56c96a95e31780e3015b3e637e9.zip |
refactoring: Use 'ifUndefined*' consistently.
Added some error checking
-rw-r--r-- | src/models/News.ts | 4 | ||||
-rw-r--r-- | src/models/RecipePreview.ts | 16 | ||||
-rw-r--r-- | src/models/Service.js | 13 | ||||
-rw-r--r-- | src/models/User.ts | 4 |
4 files changed, 28 insertions, 9 deletions
diff --git a/src/models/News.ts b/src/models/News.ts index d1ae6fcef..a6ff86dda 100644 --- a/src/models/News.ts +++ b/src/models/News.ts | |||
@@ -19,6 +19,10 @@ export default class News { | |||
19 | sticky: boolean = false; | 19 | sticky: boolean = false; |
20 | 20 | ||
21 | constructor(data: INews) { | 21 | constructor(data: INews) { |
22 | if (!data) { | ||
23 | throw Error('News config not valid'); | ||
24 | } | ||
25 | |||
22 | if (!data.id) { | 26 | if (!data.id) { |
23 | throw Error('News requires Id'); | 27 | throw Error('News requires Id'); |
24 | } | 28 | } |
diff --git a/src/models/RecipePreview.ts b/src/models/RecipePreview.ts index 351ecf765..4d2cc8450 100644 --- a/src/models/RecipePreview.ts +++ b/src/models/RecipePreview.ts | |||
@@ -1,5 +1,13 @@ | |||
1 | // @flow | 1 | // @flow |
2 | 2 | ||
3 | interface IRecipePreview { | ||
4 | id: string; | ||
5 | name: string; | ||
6 | icon: string; | ||
7 | featured: boolean; | ||
8 | aliases: string[]; | ||
9 | } | ||
10 | |||
3 | export default class RecipePreview { | 11 | export default class RecipePreview { |
4 | id: string = ''; | 12 | id: string = ''; |
5 | 13 | ||
@@ -11,9 +19,13 @@ export default class RecipePreview { | |||
11 | 19 | ||
12 | aliases: string[] = []; | 20 | aliases: string[] = []; |
13 | 21 | ||
14 | constructor(data: { id: any; }) { | 22 | constructor(data: IRecipePreview) { |
23 | if (!data) { | ||
24 | throw Error('RecipePreview config not valid'); | ||
25 | } | ||
26 | |||
15 | if (!data.id) { | 27 | if (!data.id) { |
16 | throw Error('RecipePreview requires Id'); | 28 | throw Error(`RecipePreview '${data.name}' requires Id`); |
17 | } | 29 | } |
18 | 30 | ||
19 | Object.assign(this, data); | 31 | Object.assign(this, data); |
diff --git a/src/models/Service.js b/src/models/Service.js index dbbd622aa..ee6fe8b6e 100644 --- a/src/models/Service.js +++ b/src/models/Service.js | |||
@@ -106,13 +106,12 @@ export default class Service { | |||
106 | 106 | ||
107 | this.userAgentModel = new UserAgent(recipe.overrideUserAgent); | 107 | this.userAgentModel = new UserAgent(recipe.overrideUserAgent); |
108 | 108 | ||
109 | // TODO: Should these also follow the 'ifUndefined*' style? | 109 | this.id = ifUndefinedString(data.id, this.id); |
110 | this.id = data.id || this.id; | 110 | this.name = ifUndefinedString(data.name, this.name); |
111 | this.name = data.name || this.name; | 111 | this.team = ifUndefinedString(data.team, this.team); |
112 | this.team = data.team || this.team; | 112 | this.customUrl = ifUndefinedString(data.customUrl, this.customUrl); |
113 | this.customUrl = data.customUrl || this.customUrl; | 113 | // this.customIconUrl = ifUndefinedString(data.customIconUrl, this.customIconUrl); |
114 | // this.customIconUrl = data.customIconUrl || this.customIconUrl; | 114 | this.iconUrl = ifUndefinedString(data.iconUrl, this.iconUrl); |
115 | this.iconUrl = data.iconUrl || this.iconUrl; | ||
116 | 115 | ||
117 | this.order = ifUndefinedNumber(data.order, this.order); | 116 | this.order = ifUndefinedNumber(data.order, this.order); |
118 | this.isEnabled = ifUndefinedBoolean(data.isEnabled, this.isEnabled); | 117 | this.isEnabled = ifUndefinedBoolean(data.isEnabled, this.isEnabled); |
diff --git a/src/models/User.ts b/src/models/User.ts index 771d11955..54a6838df 100644 --- a/src/models/User.ts +++ b/src/models/User.ts | |||
@@ -42,6 +42,10 @@ export default class User { | |||
42 | @observable team = {}; | 42 | @observable team = {}; |
43 | 43 | ||
44 | constructor(data: IUser) { | 44 | constructor(data: IUser) { |
45 | if (!data) { | ||
46 | throw Error('User config not valid'); | ||
47 | } | ||
48 | |||
45 | if (!data.id) { | 49 | if (!data.id) { |
46 | throw Error('User requires Id'); | 50 | throw Error('User requires Id'); |
47 | } | 51 | } |