Bug Fixes for the Holidays
With the holidays just finished, I've finally got some time to peer into the dank and dusty crypts that are the Github Issues pages on my projects and try to clear out some of the skeletons in those particular closets. For anyone who has been using PathJS or PollJS, I've fixed all bugs that I could reproduce. This includes:
PathJS: Doesn't work in IE7
This ended up being a bug with Internet Explorer 8 or 9 in either Compatibility Mode or Quirks Mode. IE8+ supports the "onhashchange" event, which PathJS binds to. Unfortunately, when in Quirks Mode or IE7 Compatibility Mode, this event never gets fired. The problem? It's still reported as being supported. I've added some secondary checks for IE to ensure that the proper methods get fired when in Quirks/Compatibility Mode.
PathJS: "Root Route" doesn't get executed on Android
This was just a condition of certain pieces of code being called in the wrong order. A simple re-arrangement fixed the problem, and now it works and is tested on Android 2.3.5.
PollJS: Minified file is not up to date
When I fixed the "overwrite" bug in late Novemeber, I neglected to update the minified version of the file. I've updated the minified file, and it can now be pulled into your projects to fix that bug.
In addition to fixing the issues and bugs on my existing projects, I've also been working on a project that aims to make client-side javascript logging and debugging a lot more powerful. Expect a release of Lumberjack.js sometime in the very near future.
Introducing PollJS – Javascript timers made easy.
One thing that has always caused issue when writing web applications is the issue of querying the server for long-running background tasks (generating thumbnails or PDF's, sending batch emails, etc). Often times these actions are too long-running to be contained in an HTTP request, so a short request is made and an interval is set up to begin querying for the eventual finish. This isn't a terrible way to do things, but the current implementation was lacking. For example, to kill the interval you need to assign the returned value of your "setInterval" call to a variable, and clear it out with "clearInterval". This raises the problem of variable scope. Now you need to go up and up and up, and declare a global variable to contain this interval, simply so you can kill it later.
But what if that long running job never gets executed during this particular session? And what if you have many different operations that need this type of implementation? You've now got your global namespace polluted with oft-unused variables. That's where PollJS steps in.
PollJS is a convenience wrapper for the native "setTimeout", "setInterval", "clearTimeout", and "clearInterval" methods. It wraps them with a simple definition method, and extends their functionality with additional options:
// A Basic Example
Poll.start({
"update_users",
interval: 1500,
action: function(){
alert("Updated!");
}
});
Poll.stop("update_users");
You can read more about the project, and download the source code on the Github page.
Javascript Variable History
I recently answered a Stackoverflow Question where a user wanted to know if there was a way, in JavaScript, to check if a variable has ever been a particular value. Of course, there is no default built-in way to do this, but I provided (what I think to be) a valid answer. However, after a few minutes, I looked at it and thought that it might be able to help other people as well. So here it is - Chronicle. Chronicle lets you define a special type of object, and you can check the history of that object at any point in time. Here's a quick example:
var isValid = new Chronicle(false); // Default the value to false
isValid.set("not valid"); // Set it to a string
isValid.set(true); // Set it to true
// This will return true if the value inside this Chronicle
// has ever been true, and return false otherwise.
isValid.was(false);
If anyone wants this functionality on your site, it's as easy as including/running the following javascript anywhere before you need to use a Chronicle (as long as it's within the proper scope, of course). Chronicle works in any scope, in any situation.
function Chronicle(val){
this.value = val;
this.history = [];
if(val != undefined){
this.history.push(val);
}
}
Chronicle.prototype.set = function(val){
this.value = val;
this.history.push(val);
};
Chronicle.prototype.was = function(val){
return this.history.indexOf(val) >= 0;
};
Chronicle.prototype.toString = function(){
return this.value.toString();
}