DEV Community

Cover image for Hacktoberfest PR 1
Soham Thaker
Soham Thaker

Posted on • Edited on

Hacktoberfest PR 1

Repo

https://github.com/nkronlage/JavaScripture -
A JavaScript API reference site that provides simple descriptions and interactive examples. The deployed site can be found here.

Issue

As per the repo's readme, the process of adding a fix to this repo was to directly create a PR and put a merge request so no issue was opened for this PR.

PR

https://github.com/nkronlage/JavaScripture/pull/40

Process

The process was to fork the repo, create a feature branch, add all changes to that branch and issue a PR for the changes that were to be merged.

Setup

The setup for this project was quite simple. After cloning the repo, I ran an npm i followed by node build.js command to run the project. I ran into an issue of tmp folder not found which I was easily able to fix by manually adding a tmp folder.

Bug Fix

This PR was primarily a tiny bug fix related to Promises in JS specifically how they were resolved/rejected. When we write a Promise code in JS, the order of arguments that a Promise class returns is in the form of resolve, reject to the callback function. Considering this repo is an interactive JS API reference site, I fixed an issue for the code that explained how finally() function works in a Promise class. The code had a JS playground where it shows how the finally() function is executed upon promise resolution/rejection. It had a very simple example which shows that when a value of a random number is less than 0.5 the promise will resolve otherwise will get rejected. In the original code when the condition is satisfied it resolves the promise, however, technically it rejects the promise because resolve is given the value of reject and vice versa in the callback function since the arguments were jumbled up in the form of reject, resolve. This PR fixed that issue and promises are resolved or rejected properly, showing the correct log to the console. The deployed changes can be found here specifically finally block. The way to fix this bug was to make a simple code change by adding resolve to the first argument and moving reject to the second argument. Then I built the project again and it regenerated the documentation files thereby fixing the issue.

Before Fix - from the deployed site

Image description

In the above picture, the value of the x is 0.39 which is < 0.5. The promise is resolved as per the call however on the right we can see that the promise was in fact rejected.

After Fix - from the deployed site

Image description

In the above picture, the value of the x is 0.30 which is < 0.5. The promise is resolved as per the call which was the expected behavior.

Learning Outcomes

This was my first ever contribution to an open-source project which I never wrote to begin with so for that reason I kept this PR very tiny just to help me get in the groove of open-source contribution. Initially, I was lost on how this project worked, what's its purpose, etc. But as I read the readme.md and played with the deployed project I came to know what exactly the project is all about which is what I'd do every time I'm going to work on any new project from now on; utilize its features to help me understand different the aspects of the project. Besides, it was a quite smooth process for me to fix the issue and get it merged since I only touched the necessary parts of the code.

Interactions

I was amazed to see how welcoming and helpful the open-source community is. The project owner left a nice comment for me. They also reviewed and merged my PR quickly.

Top comments (0)