bfcapell
bfcapell

Reputation: 424

Backbone on BlackBerry OS5 - is it possible?

I'm developing a mobile application using Backbone, jQueryMobile and Phonegap. The app works great on Android, iOS and BB >= 6, but on BB5 as expected there are countless issues coming up.

I'm now facing problems with Backbone itself. I'm debugging it and looks like the problem is in the routes definition. The application crashes on start time due to something related to it (still investigating, but debugging is painful for BB5...).

Also, I read that BB5 won't play nice with hash listening, which Backbone relies on to do the navigation, so I am wondering if somebody has been able to create a backbone app on OS5, or is it simply not possible?

Upvotes: 1

Views: 412

Answers (2)

Ryan Harmuth
Ryan Harmuth

Reputation: 355

It is probably not worth it in most cases but this is doable.

I managed to get an app running after quite a bit of work - the javascript support is really not great in OS 5.0 and debugging is very very slow as suggested in bfcapell's answer.

To get backbone to work you need to comment out the code that uses the hashchange event to handle url changes (this is assuming that the router is being used). THere is a fallback in backbone which uses setinterval to poll for changes.

    // Depending on whether we're using pushState or hashes, and whether
// 'onhashchange' is supported, determine how we check the URL state.
/*if (this._hasPushState)
{
    alert('pushstate');
    $(window).bind('popstate', this.checkUrl);
} else if (this._wantsHashChange && ('onhashchange' in window) && !oldIE)
{
    alert('hashchange');
    $(window).bind('hashchange', this.checkUrl);
} else if (this._wantsHashChange)
{*/
    this._checkUrlInterval = setInterval(this.checkUrl, this.interval);
//}

The foreach method in underscore also needs to be modified to not use the native foreach method. This is needed for collections to be rendered correctly.

var each = _.each = _.forEach = function (obj, iterator, context)
{
  if (obj == null) return;

  /*if (nativeForEach && obj.forEach === nativeForEach)
  {
      obj.forEach(iterator, context);
  }
  else*/
  if (obj.length === +obj.length)

The above should get at least backbone mostly working. (I say mostly because I have a completely working app but I suspect to find a couple more OS5 specific issues in time).

Upvotes: 0

bfcapell
bfcapell

Reputation: 424

I'm updating this question just in case someone faces the same issue:

Short story: it's not possible to run Backbone on OS5. I debugged into backbone and some instructions with regular expressions were causing a crash. Even if these are fixed in the future, we determined that the js support was simply not good enough and finally discarded the OS5 version.

Upvotes: 2

Related Questions