Using dsHistory Is Easy!


If you really want to know how to use dsHistory in your own app, please check out the Usage wiki on Google Code. Otherwise, take a look at the quick overview below and then look at the page source to see how this demo uses it.

To get started, just call dsHistory.addFunction(functionToCall, functionScope, arbitraryArgPassedToFunction) to add a function to the history stack. If you want to add a name / value pair to the history stack, just call dsHistory.setQueryVar('name', 'value'). To remove a name / value pair from the history stack, call dsHistory.removeQueryVar('name'); the value will come with it. Once you're finished adding to and removing from the window hash, you can update it in the browser and bind a history event and function to it using dsHistory.bindQueryVars(functionToCall, functionScope, arbitraryArgPassedToFunction).

Keep in mind that dsHistory is only meant to be used once there are two functions on the history stack. Therefore, you'll need to add your first function to the stack at some point before the UI has finished loading and before the user has had a chance to interact with your app. In other words, when the visitor hits the back button, we are assuming that the function at the top of the stack is our current position and so it always calls the second-to-last function. Because dsHistory uses an execution queue to spool up all of your addFunction and bindQueryVars calls actions until everything in the library has initialized, you don't have to worry about waiting for the internals of dsHistory to finish loading before you start using it.

It's easy -- try it out below!

Where are we in the stack?

alert('My base function');

Add a simple function to the history stack...

dsHistory.addFunction(function() { });  Add Function

Add / removing / binding query vars...

dsHistory.setQueryVar('', ''});  Set Name-Value
dsHistory.removeQueryVar(''});  Remove Name-Value
dsHistory.bindQueryVars(function() { });  Bind Query Vars