-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor HelpComponent #418
Changes from 2 commits
bcec867
8549b9a
ca2c9e4
bb37a34
77e3a5f
ffd6138
ef1e947
aa31c0c
0d30ce6
1e24dd5
3f0a14a
d1658e2
4a48f94
52fd367
a05eba9
7d7268a
22c7064
eefa988
907fd87
a65b5a7
ed09f83
bc5a3e9
cc898d9
ce2609b
43c37b7
0b0db5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -5,25 +5,35 @@ export default class HelpService extends Service { | |||
constructor(app, serviceName="HeaderService"){ | ||||
super(app, serviceName); | ||||
this.App = app; | ||||
this.HelpCache = {}; | ||||
} | ||||
|
||||
async setData(path) { | ||||
let pathWithExtension; | ||||
|
||||
if ((/\.[^/.]+$/.test(path))) { | ||||
pathWithExtension = path; | ||||
} else { | ||||
pathWithExtension = `${path}.json` | ||||
if (this.HelpCache[path] != undefined) { | ||||
if (this.HelpCache[path] != "") { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Aringoaway I was thinking, do we really need this condition? Seems redundant to me, because we are setting an empty string as a value to the cache, if the content has not been retrieved asab-webui/src/services/HelpService.js Line 45 in 8549b9a
So I suggest a refactoring
|
||||
this.App.Store.dispatch({ | ||||
type: HELP_CONTENT, | ||||
content: this.HelpCache[path] | ||||
}); | ||||
return; | ||||
} | ||||
this.App.Store.dispatch({ | ||||
type: HELP_CONTENT, | ||||
content: "" | ||||
}); | ||||
return; | ||||
} | ||||
|
||||
try { | ||||
const ASABLibraryAPI = this.App.axiosCreate('asab_library'); | ||||
let response = await ASABLibraryAPI.get(`/library/item/Help/${pathWithExtension}`); | ||||
let response = await ASABLibraryAPI.get(`/library/item/Help/${path}`); | ||||
if ((response.status == 200) && response.data) { | ||||
this.App.Store.dispatch({ | ||||
type: HELP_CONTENT, | ||||
content: response.data.content | ||||
}); | ||||
this.HelpCache[path] = response.data.content; | ||||
} | ||||
} catch (e) { | ||||
console.warn(`Help service can't retrieve data for ${path}`, e); | ||||
|
@@ -32,6 +42,7 @@ export default class HelpService extends Service { | |||
type: HELP_CONTENT, | ||||
content: "" | ||||
}); | ||||
this.HelpCache[path] = ""; | ||||
} | ||||
} | ||||
} | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Aringoaway It does not have to be
async
since there is no async actionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Aringoaway btw.
setData
is not a good name for it, since all you do is setting the path