A simple javascript routing library

This one is going to be my second project that i decide to take on today. It is going to be a simple javascript library that routes webpages according to there hash. This is very important from what i think could be used in One Page Applications .Because of recent trend there has been an approach to shift as much processing to client side without compromising the server security and router is the first step in any framework to handle the request so here it comes. Now again like my last post which i am still not sure why i can't see in my dashboard till now, i will be going on using strict and native JS for writing the application. So the router should be

  • Able to listen to hash changes
  • Have history api implemented
  • Should be simple to use

Now i marked history api as important because in one page app you can't expect the users to forget about the back button. It is always going to be there and you should be prepared for that. Anyway the fist task is the git repo and here is the link to the same.

Now after initializing the repo i need a couple of calls to get the hash state after the page has loaded completely. Well the good news is that now i can call functions easily based on url although i will have to say that it was a little difficult because of the hash change listener. Which i was using by directly implementing window.onhashchange which did not give me access to the this object in the js and because of which i was not getting the url map on change of url hash but that was taken care of as could be seen in the router constructor function. Well i am leaving the history api from the first version will come back to it in a couple of days as i am really bored of working on two continuous js projects , me being a backend developer want to get into some of that stuff. But again to make a release on this library i need to add some essentials that can be used to make post request and get request to the server so here they come.Although i am going to write a simple XHR wrapper for it, nothing fancy there just to keep things simple and finish off this project so i can get a move on to others. Well the xhr interface is finished time for me to publish this library and move to something in backend. I am thinking in the lines of an interface library for mysql in c++ . The current implementation is well, too old , I think it needs something out of the box. So here i come my next project. Hope you like this one and do remember to post bugs on git so i can resolve them. After all there is only so much i can code without the codes being tested. And PS let the history api sit in a grave for now, I will come to it later but definitely not today.

A little Javascript typewriter effect

Well to start off the blog that i meant to from a long time i choose to take on a very simple task. I will be creating a js library for the fancy typing effect that we see in lots of websites today. So the name of the git repo is typejs in my git profile . First thing i decide to do is to go strict for the js. Now the next task is creating a prototype which i decided to name as typejs again just to keep things simple. A couple of functions that i think that should be there in this library are the option to

  • Add content
  • Remove content
  • append content
  • delete word
  • change the speed of typing

So now i have the speed stored in a class variable. Time to try with something as simple as add content which is going to be my first task. So addition of content using a recursive call was relatively simpler task. Time to add a function to remove such content. Which turns out to be a simple task after all.Simple recursive call after removing the last element did the task. Now at this point a bug got me thinking what if the addition and clear function are called at the same time. Better to add a callback function when they are completed ,Will come to this point later on.

Moving to append content which i just realized is the same as add data but just to be same i am adding a flush function just to clear off the initial canvas that we are going to be working on. Simply implemented with no issues.

Now deleting word is the only function that is remaining so going to initialize a new function for it now, which i copied mostly from clear function.

Now that i have all the functions working i think it is time to wrap up by making it usable, Yes i mean about the locks, but implementing lock and queue is a hastle so i will simply add a callback function to all of the functions just to make stuff simpler for me.

Now with all done i can move on to write documentation which i suck at so i am simply going to write how to call the functions.

I am rusty on writing readme files 2 commits just to get it working. Anyway now that the code is up and finished feel free to use and add bugs to it. Don't judge me on this blog this is the first with promise of many more to come and hopefully me getting better at the job. Its almost my breakfast time now. So let me grab a quick bite before i more on to next project.

Here is a quick link to the project LINK

GitHub – georoot

rahul bhola

Bengaluru,India

Just a curious computer enthusiast