0

I have run into some problems with using durandaljs as a framework for html5 mobile apps, I have never had to deal with this on a web application.

Whenever there is any kind of error, durandaljs pretty much packs up, the router stops working etc. It's not always my code as sometimes error handling doesn't solve the problem. I use phonegap and very often phonegap gets temperamental and calls to plugins may fail or crash or something equally inexplicable. When this happens, the only way around it is to shutdown the app and start it up again.

My users have a very short fuse and asking them to shutdown the app and log back in every time a bug rears up would definitely ensure the app does not make it past the pilot phase. What I want is to be able to have a button that the user can click and it would restart durandaljs as if the app were starting up for the first time.

My question is, is there a way to restart durandaljs when this happens without shutting down the app and starting it up again; I know AngularJS allows something like this.

Thanks

Obi
  • 3,091
  • 4
  • 34
  • 56
  • I don't know much about PhoneGap, but this is certainly possible. Throw away your RequireJS context, clear the `application-host` from the DOM, start a new RequireJS context (this is to ensure everything is reloaded instead of re-used), and call `app.start` again. – Kyeotic Jan 06 '14 at 17:03
  • Thanks @Tyrsius, you make it sound easy. How would you 'throw away' your Requirejs context? – Obi Jan 06 '14 at 19:19
  • Take a look [at the multiversion docs](http://requirejs.org/docs/api.html#multiversion) to see an example of multiple require instances. By "throw away" I just mean make a new instance, and use it. The new instance will reload all the components as if they had never been used before. – Kyeotic Jan 06 '14 at 20:35
  • 1
    You could display a native button wiring it up to exexute the initialization same way you launch it. Eg Android as in your Main activity – zewa666 Jan 07 '14 at 07:30

1 Answers1

0

I found a pretty easy way to do this. Simply call

location.reload
Obi
  • 3,091
  • 4
  • 34
  • 56