Created
February 27, 2014 01:27
-
-
Save bguiz/9242451 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.js"></script> | |
<script src="http://builds.emberjs.com.s3.amazonaws.com/tags/v1.0.0/ember.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script type='text/x-handlebars' data-template-name='application'> | |
{{#link-to 'foo'}}Go to Foo{{/link-to}} | |
<div>{{outlet}}</div> | |
</script> | |
<script type='text/x-handlebars' data-template-name='foo'> | |
<h1>foo</h1> | |
{{#each}} | |
{{name}} | |
{{else}} | |
There is no foo. | |
<p><a href="http://emberjs.com/guides/routing/asynchronous-routing/#toc_recovering-from-rejection">Successfully recovered from promise rejection in route</a></p> | |
{{/each}} | |
</script> | |
</body> | |
</html> |
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
var App = Ember.Application.create({ | |
LOG_TRANSITIONS: true | |
}); | |
App.Router.map(function() { | |
this.route('foo'); | |
}); | |
App.FooRoute = Ember.Route.extend({ | |
model: function() { | |
return App.Foo.findAll().then(function(response) { | |
return response; | |
}, function() { | |
console.log('foo route caught error', arguments); | |
return []; | |
}); | |
}, | |
actions: { | |
error: function() { | |
console.log('foo route actions error', arguments); | |
} | |
} | |
}); | |
App.Foo = Ember.Object.extend({}); | |
App.Foo.reopenClass({ | |
findAll: function() { | |
var req = $.ajax({ | |
url: '/api/which/will404' | |
}); | |
//"The router considers any object with a then method defined on it to be a promise." | |
//Source: http://emberjs.com/guides/routing/asynchronous-routing/#toc_the-router-pauses-for-promises | |
console.log('typeof req.then:', (typeof req.then)); | |
return req; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment