Created
February 11, 2014 03:28
-
-
Save valer-cara/8928825 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make all controllers have a reference to the alerts controller. | |
# Kudos 1 - `needs` is a `concatenatedProperty`, so that specifying it further | |
# in the iheritance chain it gets added up | |
Ember.ControllerMixin.reopen( | |
needs: ['alerts'] | |
alert: (message, type) -> | |
@get('controllers.alerts').pushObject( | |
type: type || 'success' | |
message: message | |
) | |
) | |
# Kudos 2 - debounce makes sure each message gets 1 second of show time, and it's a one-liner | |
App.AlertsController = Ember.ArrayController.extend( | |
content: [] | |
contentObserver: ( -> | |
Ember.run.debounce @, @shiftObject, 1000 | |
).observes('content.@each') | |
) | |
# How to use | |
App.PostsController = Ember.ArrayController.extend( | |
actions: | |
buttonPush: () -> | |
@alert('shithead') | |
) | |
# Template here: `alerts.hbs` | |
{{#each}} | |
<p>{{message}}</p> | |
{{else}} | |
<p>No alerts</p> | |
{{/each}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment