Skip to content

Instantly share code, notes, and snippets.

@valer-cara
Created February 11, 2014 03:28
Show Gist options
  • Save valer-cara/8928825 to your computer and use it in GitHub Desktop.
Save valer-cara/8928825 to your computer and use it in GitHub Desktop.
# 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