12.28.2013

Flash Messages in Ember (or how to use a proxy object to update Controllers outside of the normal route based approach)

In many different frameworks there is the concept of a flash; a short message to alert a user that something happened on the server backend. This is usually display in the form of a visual alert ala http://getbootstrap.com/components/#alerts

The way I wanted to accomplish this was to pass an additional object in the JSON result of any request. In the form

However, because I want this functionality available anywhere in the App, not just in a flash route, I had to get a bit creative. The route (no pun intended) that worked the best is to use a proxy object set on the App and then bound to the controllers content property.

In the model definition I used the didLoad event to have the model place it's self into the proxy

Finally I created a route subclass that will add the controller to every route

Thats it, I hope it helps you out.

No comments: