Created
August 27, 2015 20:40
-
-
Save rondale-sc/ca129d5e3f1112f1b6cd 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
import Ember from 'ember'; | |
const slice = Array.prototype.slice; | |
const computedPromise = function() { | |
const fn = slice.apply(arguments, [arguments.length-1, arguments.length])[0]; | |
const dependentKeys = slice.apply(arguments, [0, arguments.length-1]); | |
return Ember.computed(...dependentKeys, function() { | |
const PromisableObjectProxy = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin); | |
const promise = fn.apply(this); | |
return PromisableObjectProxy.create({ | |
promise: Ember.RSVP.resolve(promise) | |
}); | |
}); | |
}; | |
export default Ember.Service.extend({ | |
store: Ember.inject.service('store:main'), | |
token: Ember.computed(function() { | |
return 'secret'; | |
}), | |
currentUser: computedPromise('token', function(){ | |
return this.get('store').find('user', { token: this.get('token') }).then(function(users) { | |
return users.get('firstObject'); | |
}); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment