Created
May 24, 2015 23:45
-
-
Save lilac/999a3fa1fc265c3688bf to your computer and use it in GitHub Desktop.
Ember PromiseProxyMixin
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
<!DOCTYPE html> | |
<!-- | |
Created using JS Bin | |
http://jsbin.com | |
Copyright (c) 2015 by anonymous (http://jsbin.com/hizoperevo/1/edit) | |
Released under the MIT license: http://jsbin.mit-license.org | |
--> | |
<meta name="robots" content="noindex"> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Ember Starter Kit</title> | |
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.css"> | |
<link rel="stylesheet" href="http://css-spinners.com/css/spinner/spinner.css" type="text/css"> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<script src="http://builds.emberjs.com/tags/v1.11.3/ember-template-compiler.js"></script> | |
<script src="http://builds.emberjs.com/tags/v1.11.3/ember.debug.js"></script> | |
<style id="jsbin-css"> | |
/* Put your CSS here */ | |
html, body { | |
margin: 20px; | |
} | |
</style> | |
</head> | |
<body> | |
<script type="text/x-handlebars"> | |
<h2>Welcome to Ember.js</h2> | |
{{outlet}} | |
</script> | |
<script type="text/x-handlebars" data-template-name="index"> | |
{{#if isPending}} | |
<div class="spinner-loader">Loading...</div> | |
{{else}} | |
Logged in as {{ content.user }} | |
{{/if}} | |
</script> | |
<script id="jsbin-javascript"> | |
App = Ember.Application.create(); | |
App.Router.map(function() { | |
// put your routes here | |
}); | |
/* | |
App.IndexRoute = Ember.Route.extend({ | |
model: function() { | |
return [ | |
'red', 'yellow', 'blue']; | |
} | |
});*/ | |
var ObjectPromiseController = Ember.Controller.extend(Ember.PromiseProxyMixin); | |
App.IndexController = ObjectPromiseController.extend( | |
{ | |
init: function() { | |
this._super(); | |
this.set('promise', fakeFind({'user': 'ember'}, 1000)); | |
} | |
} | |
); | |
function fakeFind(data, duration, shouldReject) { | |
return new Ember.RSVP.Promise(function (resolve, reject) { | |
Ember.run.later(function () { | |
if (shouldReject) { | |
reject('O NOES IT DIDNT WORK'); | |
} else { | |
resolve(Ember.Object.create(data)); | |
} | |
}, duration); | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment