aknuds1 / staterouter.js

Simple JavaScript HTML5 routing library built on top of History.js
22 stars 2 forks source link

staterouter.js + jQuery Address #4

Closed gregipp closed 11 years ago

gregipp commented 11 years ago

I've been using staterouter.js but am currently looking at switching over to jQuery Address instead of History.js due to the lack of development on the latter.

I'll look at modifying staterouter to support jQuery Address since the routing pattern you have set up follows standards and works nicely. It's a great alternative to setting up Ember or Backbone for really quick projects.

Any thoughts on the best way to do this? I was deciding on whether to create a function that detected History or Address and branched within staterouter.js at the necessary points, or to maintain two different core .js files for either library.

aknuds1 commented 11 years ago

I wasn't aware of jQuery Address, but as it doesn't implement the HTML 5 History API AFAICT I'm not sure how well it'd map to StateRouter.

In any case, StateRouter is really simple, and should be easy to modify for your purposes. I'd suggest using the Jasmine specs as your starting point (as they define what the library is to do) and change the innards until the library does what you want.

gregipp commented 11 years ago

It uses history, and adds a fair bit of additional functionality. I'll get going on this later in the week, and keep everything TDD via Jasmine. My goal is to write something that auto-detects jQuery Address or History.js and keeps a single staterouter.js core.

Thanks for the response!

aknuds1 commented 11 years ago

Cool, let me know how you fare :) From further research it seems that Address does implement the History API (pushState/popState etc.), the info I dug up on it was probably out of date.

gregipp commented 11 years ago

I spent some a few hours with this over the last couple weeks. Turns out it would be a bigger job that I had hoped to get the two libraries to play nice. Conceptually, jQuery Address relies more on triggered callbacks than History.js does, and while the nomenclature is similar, things like .state() don't map directly at all.

If it were to be done right, the bulk of what staterouter.js does would be fired within the $.address callbacks rather than acting as the trigger for the $.History state changes. It wouldn't be that hard, but I don't have time right now. Hopefully within the next month or two.