Code Review Friday: (Let's Improve your code, ask Corvid Master)

June 26th, 2020
Join this week code review organized by Corvid master,
Comment your code below(as per instruction) we will analyze provide you suggestion or refactored code that will be easy to read, to modify, and plenty of good practice.

We also welcome experience corvid forum members to share the knowledge and expertise.

Instructions:

*1: FULL PAGE CODE is recommended
*2: Include database structure like Collection name & Field type (if you refer them in the code)
3: Is this a live site? If so, drop a link so, we can check the code.
4: Videos or Images for explanation of what the code does is useful!
Marked * are required

Don’ts

1: Do NOT include any sensitive code (like passwords, secrect key).

// try to rewrite it as xxx if it's used inside the code
const key = "XXX-XXX";

2: Asking any questions unrelated to code review or corvid
3: Screenshot the code and not pasting the code in text format
4: Code that was not working before and asking to fix (Please create a new post in the community, This Post is dedicated to improve your current working code)

Comment not related to refactor for the code will be get deleted to organize

Notes

  • We do code review every friday PST timezone!

  • This post will be locked after 24 hours

1 Like

Give it to us guys!!!

Hello Scott,

i don’t wanna miss the friday’s-review :grin:

export function table1_rowSelect(event) {
    setTimeout (()=>{
        $w('#dataset1').onReady( () => {
 let currentRowIndex = event.rowIndex
            console.log(currentRowIndex)    
 let URL = $w('#dataset1').getCurrentItem().url
            console.log(URL)
            
 let myURL = $w('#dataset1').getCurrentItem()["link-tutorials-title"]
 let contentLink1 = $w('#dataset1').getCurrentItem()["link-tutorials-title"]

            console.log(myURL)
            $w('#BTNgo').link = myURL
        } );
    },1)
}

My question is, how can i improve that little piece of code to cut out —> “setTimeout” of my code. Don’t wanna use it, but could not find a solution without it.

Tried to use “onReady” and event async-await, but all ran into an error :tired_face:

/*

Try to use a $w selected to catch the event instead of binding using the property panel

*/

$w.onReady(() => {
  $w('#dataset1').onReady(() => {
    init();
  });
});



function init() {
 // page element and dataset are ready to use

  $w('#table1').onRowSelect(event => {

 const currentRowIndex = event.rowIndex;
    console.log(currentRowIndex);
 
 const item = $w('#dataset1').getCurrentItem();
 const URL = item.url;
    console.log(URL);

 const myURL = item["link-tutorials-title"];
 const contentLink1 = item["link-tutorials-title"];

    console.log(myURL);
    $w('#BTNgo').link = myURL;

  })

}


Ok, THX!
I will check this out tomorrow.

Have a nice weekend! :grin:

EDITED:


YES, OK I GOT IT ! (THX) ! Learning every friday some new stuff.

Closing the thread
hope this was useful,
We(Corvid master) will do Code review on every Friday ,
get ready for the next code review on 4th July, 2020
Happy coding :v: