Ember.js 2.1 and 2.2 Beta released


Ember.js 2.1 is a minor version of Ember, with only additional features, released today. This version represents more than 82 direct contributors and more than 850 submitted work.

Ember.js 2.2 beta is a branch of Ember. It will be released stably in about six weeks and will be released today.

New features in Ember.js 2.1

The changes to Ember’s API in 2.1 are backward compatible. A summary of the new features released today is as follows.

{{get}} helper

This {{get}} The helper allows dynamic attribute lookup of objects in the template. For example, these two usages are equivalent:

{{user.name}}
{{get user "name"}}

Attributes with string values ​​can be passed as the second parameter, so that both objects and attributes are dynamically read. E.g:

{{get user somePropertyName}}

Related documents get,reference API documentation.

thank you very much @jmurphyau To achieve this feature, and his excellent
ember-get-helper The plug-in demonstrates the usefulness of this assistant.Use his
Embers truth helper The plugins in the 1.13 code base are highly recommended.

{{each-in}} helper

This {{each-in}} The helper iterates over the keys and values ​​of the object.It is similar in concept to for (key in object) { The syntax of JavaScript.For example, this code will display a list of all attribute names and values user
purpose:

<ul>
{{#each-in user as |key value|}}
  <li>{{key}}: {{value}}</li>
{{/each-in}}
</ul>

when using it {{each-in}}, The iterative list of keys will be unbound.If a new attribute is set user with user.newProp = 'newVal';, The new attributes will not appear.

Related documents {{each-in}} Helper, see API documentation.

Thank you @tomdale For achieving this feature, and thanks
@miguelcamba For his follow-up PR.

Registration and container reform

The Ember.js registry and container are one of the most widely used private APIs in the framework. They provide one of the only ways to find any object in Ember’s dependency container.

We are committed to stabilizing this part of the framework and providing public APIs.This first step creates a standardized way of interaction register with lookup We hope to continue into the 2.x cycle and beyond.

In 2.1, Ember.Application The instance is passed as the first parameter to initializer
hook. initializer Hooks are places where you can configure dependencies between object types and you can register factories.Several public APIs will exist in Ember.Application Examples, some of which are new:

  • register -Registered factory
  • inject -Inject one factory into another factory, or all factories of one type
  • unregister -Remove factory from registration
  • resolveRegistration -Get registered factory
  • hasRegistration -Check the registered factory
  • registerOption, registeredOption, registerOptions, registeredOptions,
    registerOptionsForType, registeredOptionsForType It manages the options of the factory (it is a singleton and can be instantiated).

Ember.ApplicationInstance The instance is passed as the first parameter to
instanceInitializer The hook in 2.1. instanceInitializer The hook is where the factory can be obtained from the configured and launched application.A related public API exists in Ember.ApplicationInstances:

  • lookup -Get an instance of a factory (with dependencies)

You can find updates to the initializer guide in the improved initializer Application problem section. The API documentation has been similarly updated in the following locations Embers application namespace, Ember.Application Class, and Ember.ApplicationInstance class.

This feature also introduces two small deprecations:

  • It is not recommended to use the two parameters of the initializer hook
  • Make a call appInstance.container.lookup It is not recommended to use the first parameter of the instance initializer appInstance.lookup.

We hope to change the API in the future. It is not recommended that you use the deprecated feature, but you can safely mute the deprecation message and continue to use the feature until its removal date.

Thank you so much for tireless people @dgeb Because of his work on RFC, implementation, and documentation of these changes. They represent a major improvement in Ember’s dependency injection system.

Deprecation and warning handlers

Before Ember 2.0, it was clear that the tools used to manage deprecation were poor. One of the reasons for this is the lack of public and documented APIs to determine how to deal with deprecations and warnings. 2.1 A suitable API is introduced for our tool to build.

The default behavior for deprecation or warning is to log in to the console. To change this behavior, register the handler and write custom logic.For example, this handler will throw an exception for any deprecated messages with words
should among them:

Ember.Debug.registerDeprecationHandler((message, options, next) => {
  if (message.indexOf('should') !== -1) {
    throw new Error('Deprecation message with should: '+message);
  } else {
    // defer to whatever handler was registered before this one
    next(message, options);
  }
});

In this example, all warnings are muted:

// next is not called, so no warnings get the default behavior
Ember.Debug.registerWarnHandler(() => {});

The handler provides the following data through parameters:

Deprecation handlers will also be provided:

Starting from Ember 2.0, deprecate with warn Call must provide id Options, and deprecate The call must be provided separately until Options. Plugins that did not provide this data during 2.x will trigger a deprecation warning.

For more information, see Ember.Debug
API documentation.This API can be used with previous Ember versions
Embers debug handler polyfill, in spite of id with until The data was not available until Ember 2.0.

Thank you @rwjblue Used to publish this API and polyfill plug-ins, and @mixonic
For RFC.

For more detailed information about the changes to Login 2.1, please check
Ember.js 2.1.0 change log.

Ember.js 2.2 beta

Ember 2.2 has no new features. In the Canary cycle that led to this Beta version, the core team and the community were mainly focused on performance improvement or functional work still lagging behind the feature flag.

For more detailed information about the changes in landing 2.2, please check
Ember.js 2.2.0-beta.1 change log.



Leave a Reply

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