Ember Latest
The latest build of Ember.
HTML
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v2.0.0.js"></script>
<script src="http://builds.emberjs.com/ember-latest.js"></script>
<script type="text/x-handlebars" data-template-name="application">
<h1>ember-latest jsfiddle</h1>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<h2>Index Content:</h2>
<button {{action 'addItem'}}>Add random item</button>
{{length}}
</script>
CSS
h1 { font-size: 1.6em; padding-bottom: 10px; }
h2 { font-size: 1.4em; }
ul { padding: 15px; font-size: 1.4em; color: green; }
JavaScript
App = Ember.Application.create({});
var get = Ember.get;
var set = Ember.set;
App.IndexRoute = Ember.Route.extend({
model: function(){
return new Ember.PolyfillSet([{ firstName: 'Jason' }, { firstName: 'Matt' }, { firstName: 'Mike' }]);
}
});
App.IndexController = Ember.ObjectController.extend({
actions: {
addItem: function () {
get(this, 'model').add(Math.round(Math.random(0, 100) * 100));
}
},
length: Ember.computed('model.length', function() {
return get(this, 'model.length');
})
});
Ember.PolyfillSet = Ember.Object.extend(Ember.MutableArray, {
_content: null,
length: 0,
size: Ember.computed.readOnly('length'),
init: function (items) {
this._super.apply(this, arguments);
var set = new Set();
this.set('_content', set);
if (items && items.length) {
this.addObjects(items);
}
},
addObject: function (item) {
var content = get(this, '_content');
if (content && item) {
content.add(item);
this.set('length', content.size);
}
},
addObjects: function (items) {
Ember.EnumerableUtils.forEach(items, function(item) {
this.addObject(item);
}, this);
},
has: function(item) {
var content = get(this, '_content');
if(content && content.has) {
return content.has(item);
}
return false;
},
contains: Ember.aliasMethod('has'),
add: Ember.aliasMethod('addObject'),
remove: Ember.aliasMethod('removeObject'),
removeObject: function (item) {
var content = get(this, '_content');
if (content && content.delete) {
content.delete(item);
this.set('length', content.size);
}
}
});