Ember 1.4.0 and 1.5 Beta released


We are happy to announce that the first beta version of Ember.js 1.4.0 and 1.5 series has been released. This is the fourth cycle of the six-week release process that we started after the 1.0 release.

New features in 1.4

Property support extension

In earlier versions of Ember, if you want to observe both foo with bar on baz
You need to set both baz.foo with baz.bar As a dependent key.

var obj = Ember.Object.extend({
  baz: {foo: 'BLAMMO', bar: 'BLAZORZ'},

  something: function(){
    return this.get('baz.foo') + ' ' + this.get('baz.bar');
  }.property('baz.foo', 'baz.bar')
});

With the new attribute brace extension, you can set calculated attribute dependencies, for example:

  something: function(){
    return this.get('baz.foo') + ' ' + this.get('baz.bar');
  }.property('baz.{foo,bar}')

This allows for less duplication/redundancy when your dependent keys are mostly similar.

View original PR #3538 more details.

Ember.run.bind

Ember.run.bind Provides a useful utility when integrating with non-Ember libraries that provide asynchronous callbacks.

Ember uses a run loop to batch and merge changes. This is achieved by marking the beginning and end of Ember-related JavaScript execution.

When using events such as View’s click handler, Ember wraps the event handler in a run loop, but when integrating with non-Ember libraries, this can be tedious.

For example, the following is quite lengthy, but it is the correct way to combine third-party events and Ember code.

var that = this;
jQuery(window).on('resize', function(){
  Ember.run(function(){
    that.handleResize();
  });
});

In order to reduce the boilerplate, you can use the following to construct a callback handler that runs the loop wrapper.

jQuery(window).on('resize', Ember.run.bind(this, this.handleResize));

For more details, please refer to the recently added Operating cycle guide
(thank you very much Brendan Briggs).

With controller

This {{with}} Assistant can now accept one controller Options.Add to controller="something"
Instructions {{with}} The helper creates and uses an instance of the specified controller, and uses the new context as its content.

This is the same as using itemController Options and {{each}} helper.

{{#with users.posts controller='userBlogPosts'}}
  {{!- The current context is wrapped in our controller instance }}
{{/with}}

In the example above, the template is provided to {{with}} The block is now wrapped in
userBlogPost Controller, it provides a very elegant way to decorate the context with custom functions/attributes.

Delayed binding properties

Previously, each property bound would add a certain degree of cost (mainly related to maintaining the binding/observer itself).This leads us to limit the list of attributes that are automatically bound Ember.TextField, Ember.TextArea, And friends.This is a common source of frustration, because more and more people want to bind to HTML5 attributes, but find that to do so, they have to reopen
Ember.TextField Class and add the properties they need.

This might look like:

Ember.TextField.reopen({
  attributeBindings: ['autofocus']
});

Then from the template:

{{input autofocus=omgAutofocusMe}}

This is certainly not ideal, and will cause many problems for those who expect it to “work”.

Fortunately, this has gotten better with the release of version 1.4. In 1.4, any property bindings that did not exist when the view is first rendered will not set the observer (thus eliminating the original performance problem), but if/when it is set on the view later (after the first rendering) The property observer is set at that time.

This means that we only create observers for the actual attributes that exist, but we can list every valid HTML attribute attributeBindings Properties so that you can use them without reopening the inner class.

Starting from Ember 1.4, you should be able to use any HTML5 attributes {{input type="text"}}, {{textarea}}, with
{{checkbox}}.

Other improvements

As usual, there are numerous bug fixes and small improvements in this version. You can see a list of all changes in the CHANGELOG:

Leave a Reply

Your email address will not be published. Required fields are marked *