Outreachy weeks 5 and 6
With this blog I have reached the mid point of my internship and have successfully finished 6 weeks !!
The past 2 weeks were filled with lots of Java script coding and debugging. Periods of thinking of a logic , frustration while debugging, followed by excitement that my code finally works basically summarizes the past few days 😉
Well, Java script debugging can be a tedious task at times. I have spent hours trying to debug a small piece of code. Sometimes I start out with one error on my console and end up with 5 by the end of the day 😛 It is rightfully said that –
“It is a jackpot when you get to know Java script can be debugged.”
Having said that nothing beats the joy and satisfaction when you actually get your code working as desired !! And for that reason Java script is definitely one of my favorite languages to code it 🙂 It can turn web browsers into application platforms and is amazing for both front end and back end development !
Goals of my project
Since I am half way through the internship , this is the best time to look back and reflect on my progress so far. The goals of my project can be briefly classified into 3 parts :-
1) UI revamp
2) Standardization and refactor
I worked on the first part for about 3-4 weeks of my internship. The UI revamp for the LEL library mainly revolved around creating a more user friendly collapsible menu. This menu categorizes and displays the layers on click. One can use this menu to toggle between number of active layers, overlay layers and base layers. It is more like building the dashboard of the map to navigate between the different features !!
In these first few weeks I also worked on some existing bugs in the repo and fixed issues related to layer loading problems and problems related to zoom and bounding boxes of the map. The next step was to standardize layer code !!
I started standardization of layer code in the 4th week 🙂 The first step was to refactor the main code base. I separated and refactored code in the main html css and js files. Broke huge files into 2 where needed and also opened a few interesting new comer issues for the same to encourage community growth and participation!!
Standardization of Layer code
LEL when initially developed , had different java script files for each layer when you could logically merge some of them to use the same or similar functions. Hereby there was lots of redundant code in the library. Let me give you guys an example –
So there were 3 indigenous land layers ie the language, territories and treaties layer. These used practically the same functions and code base other that the API url that fetched that layer’s specific data. But there were 3 different JS files in the repo for these layers !! So as my first task in the standardization process I wrote one JS file to combine the functions of these 3 layers and reduce code redundancy 🙂
This seems pretty easy at first ! I thought I can just parameterize the function and pass the API urls ….
CORS error with API url’s
But nope ! That did not work This method give you a CORS error. Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources on a web page to be requested from another domain outside the domain from which the first resource was served. There was a lot of debugging me and 2 of my mentors did here !! We worked on this PR for days yet unsure of how we can resolve this error.
By now I started trying different methods to achieve this standardization. I passed the layer name and wrote a ternary condition statement or an if-else block to assign the url’s real time. This method finally worked 🙂 But there was a catch here !!
In this method I was facing variable scope problems and the function was not able to access the latest value of the variable. After a lot of thinking and debugging I have now standardized the layer code for these 3 layers !! Would never have been possible without my mentors help 🙂
In the big picture, I now know the procedure for standardizing layers and it will be easy to standardize the rest hopefully 🙂
With 6 weeks of my internship done, I am now presently working on writing tests for the layers. We recently installed and set up jasmine testing framework for the LEL repo and I am now writing tests parallely as I standardize layer code.
The process I plan to follow is standardize particular layers and then write tests for them so that they don’t break anything and are rendered properly !!
The UI revamp phase of my project was definitely the easiest and smoothest while the standardization of layer code took a while. There were times when I was clueless on how to proceed since nothing I had tried worked so far. But there is always a way to everything you just need to be patient , reach out to your mentors for help and keep working !! There are usually these 2 phases in a programmers life –
1) Don’t know whats happening – this is usually while we are stuck and are trying to fix something
2) Top of the world feeling – this is when at last you get your code working as desired and the PR gets merged !!
So keep the hard work going guys !! Code debug and test It will always work in the end !!