Ember.js: Compatibility with ES6 class syntax

Created on 2 Feb 2015  Â·  44Comments  Â·  Source: emberjs/ember.js

This would be a great feature and usable by people using 6to5 in ember-cli. What kind of work would need to go in to make this possible?

  • [x] align _super and super
  • [ ] es2016 decorators stability
  • [x] loose mode proto for IE8 (for now) we don't support IE8 in 2.0
  • [x] constructor vs init vs ..
    i suspect constructor will be the new form, with the new behaviour i would prefer, and init will fire after?...
Feature

Most helpful comment

I unlocked the conversation, but would suggest that any further discussion to lay the groundwork for this feature should happen in an issue on the RFC repository, and should probably either present or wait for a straw-man that uses JavaScript decorators.

All 44 comments

Won't be possible until js adds annotations. Also won't work in ie8.

That being said, I am sure we all want this.

It looks like Angular and TypeScript teams working together with @wycats to get a proper annotations specification (see http://blogs.msdn.com/b/typescript/archive/2015/03/05/angular-2-0-built-on-typescript.aspx). I hope this can be transpiled with Babel easily to get real ES6 class support.

The annotations proposal and a proposal for declarative properties are going to be brought to TC39 at the Paris meeting on March 24.

I anticipate support in Babel pretty quickly assuming all goes well. :smile:

@wycats we will also need jshint support, for annotations, can you apply pressure?

@stefanpenner once we have an advanced proposal, I'll try and get it done.

@stefanpenner once we have an advanced proposal, I'll try and get it done.

:+1: if we can get those tooling pieces tee'd up, we can roll this out much quicker.

@wycats we need to figure out this._super and super interop still.

@stefanpenner yeah. There's an ES7 super proposal coming up in Paris as well. I'll make sure to keep the Ember use case in mind.

@stefanpenner yeah. There's an ES7 super proposal coming up in Paris as well. I'll make sure to keep the Ember use case in mind.

thanks, keep me in the loop. I'll gladly prototype something if i have the proposal.

I'm not sure if this discussion overlaps, but the React team looks into how mixins could be expressed for ES6 classes (https://github.com/facebook/react/issues/1380). It looks like this could be done solved with an annotation on a class, too...? Just to point to another use case outside of Ember.

@donaldpipowitch awesome, good resource, will read it shortly.

I believe, as the thing to the right of extends is just an expression, and that super desugars to toMethod we may be in the clear.

/cc me

@thehydroimpulse for future reference you can use the Notifications button on any issue to get notifications without sending everyone a message :raised_hands:

@trek Unfortunately, if you're watching a project, you're technically already subscribed to all issues, but you don't get email notifications. Commenting is unfortunately the only way around it.

@thehydroimpulse, go here https://github.com/settings/notifications and enable email notifications for watched repos.

Seems like Aurelia is making use of some of the features @wycats mentioned. They are using decorators for dependency injection. Also now that IE8 support is being dropped seems like there could be some movement happening in that direction.

Also now that IE8 support is being dropped seems like there could be some movement happening in that direction.

Yes this is/was the largest barrier. The next largest is actually the copious amount of re-factoring, and the incompatibility between ES5 and ES6 classes (specifically the lack of desugaring for super).

It would be great to use ES6 super-powered methods instead of magical this._super(...)
I guess it's not possible until Ember will switch to ES6 classes (for all the base classes).
As for IE8 support - as I understand, Ember 2.0 will drop it, so it's not a problem.

Much work has been done on this, there is a pending PR by @stefenpenner that makes the required changes (still needs a few changes/fixed IIRC).

I guess it's not possible until Ember will switch to ES6 classes (for all the base classes).

For classes super works correctly, our superWrappering makes it "just work" today. Mostly we are just waiting on 3 things:

  1. decorator spec to be finalized – we can't start relying on on-finalized spec :(
  2. IE8 to be dropped
  3. extraction of the mixin helper

Without 1 + 2, 3 serves very little value in core. Although it may be provided as an add-on.

i have updated the above checkboxes (and edited some of the words)

loose mode proto for IE8 (for now)

@fivetanley im not sure what this means, but I suspect this doesn't matter as ember 2.0 drops IE8?

Can't wait!!! Has there been any work on this since the last update?

Is the decorators spec stable enough to do this now? rwjblue's project is a great step in the right direction, but having classes and decorators built-in to Ember would dramatically improve developer experiences (not to mention morale :-D).

:+1:

@rosshadden Still at Stage 1, but many improvements have been made to the spec. https://github.com/wycats/javascript-decorators/pull/36

@rosshadden yes we agree, and this is why @wycats and myself are on tc39. To push aspects of the spec that benefit our day to day forward.

In-fact the decorator spec is largely championed by @wycats

Going foward should this "feature" issue be tracked in the emberjs/rfcs repo?

^ agreed

Please link us to whatever the spiritual successor of this issue ends up being once it is created, so those of us that are interested may subscribe to it.

Thanks.

@rosshadden watching the https://github.com/emberjs/rfcs repo is the best bet for you to stay up to date on how this happens. I highly doubt whoever takes the next steps would remember to update this ticket directly, even if they knew it exists (the next person to move on it might be someone we don't know today)!

Why have we closed this before an RFC was created?

Normally such action means a rejection.

This issue tracker is for bugs only. Features go in the RFCs repository. For more details read https://github.com/emberjs/ember.js/blob/master/CONTRIBUTING.md#requesting-a-feature.

Normally such action means a rejection.

not here

basically, the primary barrier is:

EcmaScript decorators stability

We are working on it from TC39 side of things.

Why have we closed this before an RFC was created?
Normally such action means a rejection.

I understand why you might have felt that way, and we probably should have been clearer: moving to standard JavaScript classes is a top-priority for us. It requires careful design and interoperability work, and as Stef said, any plausible transition will require JavaScript decorators.

I am working on decorators at TC39 and hope to advance them far enough in the next meeting (in Munich) that we can start seriously starting to plan a transition.

I unlocked the conversation, but would suggest that any further discussion to lay the groundwork for this feature should happen in an issue on the RFC repository, and should probably either present or wait for a straw-man that uses JavaScript decorators.

Just a reminder we could very well be be doing static analysis and compiling to what decorators would compile to in Babel or TypeScript. While there are ergonomic things at steak from the consumer point of view, there are some performance benefits of doing this as well.

@chadhietala ya, if done right we can avoid the applyMixins costs we do today.

Is there any update on this? Thanks!

@karellm not yet, still work to do and decorators are only stage 2!

stage 2 means ember needs to be on it.. 😄

It looks like ES6 classes for Ember are already supported using ember-cli-babel...Is there some other "official" way to do it or is that still on hold?

@tatyahoo babel allows classes, but Ember has Ember.Object which is used throughout the framework for things like observing properties, unknown properties, etc., so moving to classes isn't so simple.

@knownasilya So does that mean that even though the below code works, it's not functioning the same as the normal way and unsafe?

import Ember from 'ember';

const {
  Component
} = Ember;

export default class extends Component {
  
}
Was this page helpful?
0 / 5 - 0 ratings