My First Contribution to Open Source

Previously I had blogged about my-note app I created via Github. Our next task was to find issues and create pull requests on the apps created by our peers. The whole process was a very exciting journey.

Steps toward Open-Source contribution

I filed two issues. One of them to improve existing code and the other one to add a new feature to a repository.

Adding a callback function to handle errors

The link to the issue could be found here. The write function in the code does not address errors that might possibly occur in case it fails. I proposed to add a callback function that outputs an error message to the web console. The pull request I created could be accessed here. It is the addition of a simple function which checks for an error and outputs the message if present.

 fs.writeFile('/note', document.querySelector('#note').innerHTML, function (err){  
    if(err) 
       console.error('Saving error', err);  
 });  
Adding a word count feature

Here are the links to the issue and the pull request I created. The project designer had created an online note-taking app with the basic functionality of saving the notes and clearing them. I thought it would be interesting to add a word count feature to improve its functionality. The app would now generate a count of words in the note upon clicking a “word count” button.

<input id="words" type="text" value="" size="6" style="float: right;"> 
<button  onClick="count_words()" style="float: right;"> Count words </button>
...
function count_words () {
 str = document.querySelector("#note").innerHTML; 
 str = str.replace(/(^\s*)|(\s*$)/gi, "");       //remove all leading and trailing spaces
 str = str.replace(/[ ]{2,}/gi, " ");            // change 2 or more spaces into a single space
 str = str.replace(/\n /, "\n");                 // exclude newline with a starting space
 document.getElementById("words").value = str.split(' ').length;  
}
Adding a text editor to my-note app

Honestly, the most exciting part of this assignment was to see how my-note app was improved by one of my peers. Checkout out more exciting works in my peer’s GitHub page. The additional feature that was added into my-note was a text-editor which was implemented using the trix-editor. Check out my app’s new look!

Open-source definitely brings us to the understanding of how we could help each other as a community.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website at WordPress.com
Get started
%d bloggers like this: