IEEE-RVCE / IEEE-RVCE/IEEE-RVCE.github.io
Documentation and code improvement
還沒有人認領這個 Issue。
- 主要語言
- JavaScript
- 星號
- 3
- 分支
- 2
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Aim
This is an umbrella issue that has the following objectives
- Show the methods of documentation
- Track documentation progress
Progress
- Remove props for components that don't need it
- Convert the
.then()promise hell into readableasync-awaitexpressions - Add in-code documentation
Information
.then() Improvements
axios.put(hostname + '/api/gallery/' + props.data.iid, values, {
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + localStorage.getItem('atoken')
},
})
.then((response) => {
if(response.data.ok === true)
setMeta({...meta, success: true})
else
setMeta({...meta, error: true})
})
.then(() => {
window.location.reload()
})
.catch((error) => {
console.error(error.response.data.status)
setMeta({...meta, error: true})
})
This piece of code can save different ways of fixing
Route 1 - Lesser .then calls
.then is not always required, except for working on a promise. Only axios here returns a promise, so it can be merged.
axios.put(hostname + '/api/gallery/' + props.data.iid, values, {
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + localStorage.getItem('atoken')
},
})
.then((response) => {
if(response.data.ok === true)
setMeta({...meta, success: true})
else
setMeta({...meta, error: true})
window.location.reload()
})
.catch((error) => {
console.error(error.response.data.status)
setMeta({...meta, error: true})
})
Route 2 - Use Async await
Consider this alternate syntax:
try{
const response = await axios.put(hostname + '/api/gallery/' + props.data.iid, values, {
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + localStorage.getItem('atoken')
},
});
if(response.data.ok === true)
setMeta({...meta, success: true})
else
setMeta({...meta, error: true})
window.location.reload()
}catch(error){
console.error(error.response.data.status)
setMeta({...meta, error: true})
}
Refer to
- (MDN)[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function]
- (Scotch)[https://scotch.io/tutorials/asynchronous-javascript-using-async-await]
JSDoc
Problem
export const component1 = (props) => {
//...
}
This component is difficult to pull out without referencing a parent component who used it.
Additionally, VSCode cannot provide autocomplete for props.
Solution
Use the JSDOC standard.
/**
* This component does x y z
* @param {{data:number[],data2:string}} props
*/
export const component1 = (props) => {
//...
}
This should explain the reason for the page and what its arguments are.
The added advantage is that VSCode (and GitHub's Markdown, if you can notice) has JSDoc integration, and can read this and provide autocomplete.
Please refer https://jsdoc.app/about-getting-started.html
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先定位 checklist 涵蓋的 frontend 元件,並查看提供的 promise 和 JSDoc 範例。完成的標準是移除不必要的 props、改善已識別的 promise 鏈,並為相關元件新增描述其用途和引數的程式碼內文件。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript
- 領域
- documentation, frontend
- Issue 類型
- 重構
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 30/100