Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jayphelps/ember-relay
That whole `Promises` thing without even paying attention.
https://github.com/jayphelps/ember-relay
Last synced: 21 days ago
JSON representation
That whole `Promises` thing without even paying attention.
- Host: GitHub
- URL: https://github.com/jayphelps/ember-relay
- Owner: jayphelps
- Created: 2013-06-27T06:38:50.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-05-04T04:25:36.000Z (over 10 years ago)
- Last Synced: 2023-03-22T22:37:16.786Z (over 1 year ago)
- Language: JavaScript
- Size: 172 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
ember-relay
===========**Note: This project is not maintained right now as I think ES6 generators + `yield` are better; or even better [ES7 `async`/`await`](https://github.com/lukehoban/ecmascript-asyncawait)**
That whole `Promises` thing without even paying attention.
Makes Promises ***act*** like they're synchronous.
```javascript
App.Profile = Ember.Object.extend({// Example using Relay.
// This code is deceptively simple. Even though we wrote the code as if
// these calls are synchronous, in reality, Relay knows you can't find the
// tweets until the User has been loaded because you told it so. Just as
// you can't display those tweets until they are ready.
usingRelay: function () {
var relay = Relay.create(this);var user = relay.findUser(1234);
var tweets = relay.findTweets(user);relay.displayTweets(tweets);
// Do something else while they're all loading
},// Example WITHOUT Relay
withoutRelay: function () {
var self = this;this.findUser(1234).then(function (user) {
self.findTweets(user).then(function (tweets) {
self.displayTweets(tweets);
});
});
// Do something else while they're all loading
},findUser: function (userId) {
return App.User.find(userId);
},findTweets: function (user) {
return App.TweetsByEmail.find(user.get('email'));
},displayTweets: function (tweets) {
// Do something with the tweets
}
});
```Under the hood, Relay wraps your methods and keeps track of the arguments you pass, calling the real implementation only after all dependencies (promises) are resolved.
###Why?
Because I'm working on an app that uses lots of promises that depend on eachother and I'm tired of writing .then(closure).then(closure) etc. I'm also semi-anal about methods vs. spaghetti closures.###License
MIT Licensed###Future
In the future I plan to make this work with anything that is Promises/A compliant, not just Ember.