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
class UsersController { | |
users: User[] = []; | |
constructor() { | |
this.fetchUsers(); | |
} | |
async fetchUsers() { | |
var result = await this.$http.get("/users/all"); // Put this in a service, obviously. userService.get() or whatever. | |
this.users = result; // Yay! The UI will automatically update to show these users. |
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
App.run([ | |
"$q", | |
function ($q: ng.IQService) { | |
// Use Angular's Q object as Promise. This is needed to make async/await work properly with the UI. | |
// See http://stackoverflow.com/a/41825004/536 | |
window["Promise"] = $q; | |
}]); |
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
Show hidden characters
{ | |
"compilerOptions": { | |
"noImplicitAny": false, | |
"noEmitOnError": true, | |
"removeComments": false, | |
"sourceMap": false, | |
"target": "es5", | |
"strictNullChecks": true, | |
}, | |
"compileOnSave": true, |
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
// 1. Old, sucky way of doing async work: callback hell! | |
function myCallback(result) { | |
this.items = result; | |
} | |
someAjaxRequest(myCallback); | |
// 2. Slightly better way using Promises! | |
someAjaxRequest().then(results => this.items = results); |
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
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> | |
<TypeScriptTarget>ES5</TypeScriptTarget> | |
<TypeScriptJSXEmit>None</TypeScriptJSXEmit> | |
<TypeScriptCompileOnSaveEnabled>True</TypeScriptCompileOnSaveEnabled> | |
<TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny> | |
<TypeScriptModuleKind>None</TypeScriptModuleKind> | |
<TypeScriptRemoveComments>False</TypeScriptRemoveComments> | |
<TypeScriptOutFile /> | |
<TypeScriptOutDir /> | |
<TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations> |
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
// Load up the RecipeViewModels stored in our index. | |
var recipeViewModel = ravenSession.Query<RecipeViewModel, RecipeViewModelIndex>() | |
.Where(r => r.Name == "Sweet honey glazed salmon") | |
.ProjectFromIndexFieldsInto<RecipeViewModel>() | |
.First(); |
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
/// <summary> | |
/// RavenDB index that is run automatically whenever a Recipe changes. For every recipe, the index outputs a RecipeViewModel. | |
/// </summary> | |
public class RecipeViewModelIndex : AbstractIndexCreationTask<Recipe> | |
{ | |
public RecipeViewModelIndex() | |
{ | |
Map = allRecipes => from recipe in allRecipes | |
let chef = LoadDocument<Chef>(recipe.ChefId) | |
let comments = LoadDocument<Comment>(recipe.CommentIds) |
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
// Listen for changes to Recipes. | |
// When that happens, update the corresponding RecipeViewModel. | |
ravenStore | |
.Changes() | |
.ForDocumentsOfType<Recipe>() | |
.Subscribe(docChange => this.UpdateViewModelFromRecipe(docChange.Id)); |
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 recipeViewModel = new RecipeViewModel | |
{ | |
Name = "Sweet honey glazed salmon", | |
RecipeId = "recipes/1", | |
PictureUrl = "http://tastyrecipesyum.com/recipes/1/profile.jpg", | |
Categories = new List<string> { "salmon", "fish", "seafood", "healthy" }, | |
ChefName = "Swei D. Sheff", | |
ChefEmail = "borkbork@bork.com", | |
Comments = new List<Comment> { new Comment { Name = "Dee Liteful", Content = "I really enjoyed this dish!" } }, | |
Ingredients = new List<Ingredient> { new Ingredient { Name = "salmon fillet", Amount = "5 ounce" } } |
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
// Query for all recipes and transform them into RecipeViewModels. | |
var allRecipeViewModels = ravenSession.Query<Recipe>() | |
.TransformWith<RecipeViewModelTransformer, RecipeViewModel>() | |
.ToList(); |