Last active
December 8, 2016 01:37
-
-
Save davelowensohn/edde4d4c222ccf466e22b60c7e9335a1 to your computer and use it in GitHub Desktop.
Hard-fought Ember promise CP that actually resolves in template
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
allVariantsQty: Ember.computed('[email protected]', function (){ | |
var result = this.get('productVariants').then(resolved => { | |
var reducedQty = resolved.map( aVar => aVar.get('inventoryQuantity')).reduce((a,b) => a + b, 0); | |
return Ember.RSVP.resolve({value:reducedQty}); | |
}); | |
return DS.PromiseObject.create({ | |
promise:result | |
}); | |
}), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the Holy Grail, for getting deep references on the model (or wherever) that play nice with templates. In this case,
product.productVariant.aggregatedQuantity
. Seems simple, but it's a real hassle, because templates aren't promise-aware & you're "supposed" to do this stuff on the route's model hook.Further reading: