Last active
August 29, 2015 14:03
-
-
Save ksol/1b47cb87fcc3300cbacb to your computer and use it in GitHub Desktop.
Example of Ember.PromiseMixin usage
This file contains hidden or 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
Application.IndexRoute = Ember.Route.extend | |
sections: | |
label1: url1 | |
label2: url2 | |
label3: url3 | |
labels: (-> | |
Ember.keys @get('sections') | |
).property('sections') | |
model: -> | |
# Keeping track of all of our promises | |
object = {} | |
for label, url of @get('sections') | |
object[label] = @get('store').findAllByUrl('modelType', url) | |
object | |
setupController: (controller, model) -> | |
@_super(controller, model) | |
controller.set('labels', @get('labels')) | |
# Filling our controllers with some accessors | |
controller.get(label, promise) for label, promise of model |
This file contains hidden or 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
Application.RowController = Ember.Controller.extend Ember.PromiseProxyMixin, | |
needs: ["index"] | |
init: -> | |
@_super() | |
# PromiseMixin requires the "promise" key to be set | |
# and fills the "content" once it is resolved, so we have to set up | |
# the right key/values here | |
# The template fills "content" with the section name | |
@set 'section', @get('content') | |
# We can grab the promise from the index controller via the section name | |
promise = @get("controllers.index.#{@get('section')}") | |
@set 'promise', promise if promise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment