Some random notes on the pangs of ember. Will be expanding as they are uncovered.
Say you have a form that maps to a model, something like:
<form>
<fieldset>
<legend>Who are you?</legend>
App = Ember.Application.create({}); | |
App.loginController = Ember.Object.create({ | |
// do login stuff | |
}); | |
App.LoginFormView = Ember.View.extend({ | |
login: null, | |
password: null, |
<html> | |
<head> | |
<script src="javascripts/jquery.js" type="text/javascript" charset="utf-8"></script> | |
<script src="javascripts/ember.js" type="text/javascript" charset="utf-8"></script> | |
<script type="text/javascript" charset="utf-8"> | |
App = Ember.Application.extend(); | |
App.Node = Ember.Object.extend({ | |
name: null, |
window.App = Ember.Application.create({}); | |
Item = Ember.Object.extend({ | |
}); | |
App.ListController = Ember.ArrayController.create({ | |
content: [], | |
currentItem: null, |
findAll: function(store, type) { | |
var root = this.rootForType(type); | |
this.ajax(root, "GET", { | |
success: function(json) { | |
store.loadMany(type, json["objects"]); | |
store.typeMapFor(type).modelArrays.forEach( function(item) { | |
item.set('isLoaded', true); | |
}); | |
App.LoginState = Ember.State.extend({ | |
enter: function() { | |
App.loginView = App.LoginView.create(); | |
App.loginView.appendTo('#content.container'); | |
}, | |
submit: function(a, params) { | |
App.loginView.loggingIn(); |
App = Ember.Application.create({}); | |
App.loginController = Ember.Object.create({ | |
// do login stuff | |
}); | |
App.LoginFormView = Ember.View.extend({ | |
login: null, | |
password: null, |
App.ajax = (url, settings)-> | |
deferred = $.Deferred() | |
settings.xhr = -> | |
xhr = $.ajaxSettings.xhr() | |
if 'onprogress' of xhr | |
context = this | |
xhr.onprogress = (e)-> | |
Ember.run(deferred, deferred.notifyWith, context, [e.loaded/e.total]) | |
xhr | |
jqXHR = $.ajax(url, settings) |
Species = DS.Model.extend({ | |
name: DS.attr('string') | |
}); | |
Person = DS.Model.extend({ | |
name: DS.attr('string'), | |
species: DS.belongsTo(Species, { embedded: true }) | |
tags: DS.hasMany(Tag, { embedded: true }) | |
}); |
test("filtered property on hasMany assoctiation", function() { | |
var File = DS.Model.extend({ | |
primaryKey: 'name', | |
name: DS.attr('string'), | |
status: DS.attr('string') | |
}); | |
var Project = DS.Model.extend({ | |
primaryKey: 'name', |