HubSpot / messenger

Growl-style alerts and messages for your app. #hubspot-open-source
http://github.hubspot.com/messenger/
MIT License
4.02k stars 406 forks source link

How to use hookBackboneAjax? #55

Closed asaenz-vmware closed 11 years ago

asaenz-vmware commented 11 years ago

Hello,

I'm currently using this messenger, and the hookBackboneAjax seems like it might save a lot of duplicate code (so I don't have to add a Messenger.post() in so many places).

The documentation on this seems a bit bare though. How exactly am I supposed to use this? I see to use "Messenger().hookBackboneAjax()", but where do I put that, and am I supposed to do something else with Backbone to get the messages showing up? Or do I need to add some kind of options to hookBackboneAjax()?

If you have an example of how to use it, that would be very helpful.

Thanks!

zackbloom commented 11 years ago

Sure

Just call:

Messenger().hookBackboneAjax()

Anytime after including the messenger and backbone javascript files. That will wrap Backbone.ajax to show error messages and retry requests. If you'd like, you can pass options to hookBackboneAjax or as options.messenger to your specific fetch call:

Messenger().hookBackboneAjax({
  progressMessage: "Making backbone request..."
});
myModel.fetch({
  messenger: {
    progressMessenger: "Fetching your model..."
  }
}
infacq commented 10 years ago

i'm not sure how to correctly / best practise for calling it, still failed when follow above example

i'm using this with requirejs.