This repository has been archived by the owner on Mar 22, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Adds Native Class Constructor Update write-up to blog #3417
Merged
jayjayjpg
merged 2 commits into
emberjs:blog/embertimes#52
from
Mi6u3l:blog/embertimes#52
Jun 21, 2018
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,36 @@ Read either on the [Ember blog](https://www.emberjs.com/blog/2018/06/22/the-embe | |
|
||
--- | ||
|
||
## [SECTION TITLE](section url) | ||
## [Native Class Constructor Update 🛠](https://github.com/emberjs/rfcs/pull/337) | ||
|
||
There is currently an open RFC proposing to change the behavior of EmberObject's constructor. | ||
|
||
Native class syntax with EmberObject has almost reached full feature parity, meaning soon Ember will be able to ship native classes. | ||
However, early adopters of native classes have experienced some serious issues due to the current behaviour of the class constructor. The issue is caused by the fact that properties passed to `EmberObject.create` are assigned to the instance in the root class `constructor`. Due to the way that native class fields work, this means that they are assigned _before_ any subclasses' fields are assigned, causing subclass fields to overwrite any value passed to `create`. | ||
|
||
The new implementation of the Ember Object would look like the following: | ||
|
||
```js | ||
class EmberObject { | ||
constructor(props) { | ||
// ..class setup things | ||
} | ||
|
||
static create(props) { | ||
let instance = new this(props); | ||
|
||
Object.assign(instance, props); | ||
instance.init(); | ||
|
||
return instance; | ||
} | ||
} | ||
``` | ||
|
||
This would assign the properties _after_ all of the class fields for any subclasses have been assigned. | ||
|
||
One thing worth mentioning is that EmberObject will likely be deprecated in the near future and that ideally for non-Ember classes (things that aren't Components, Services, etc.) users should drop EmberObject altogether and use native classes only. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd be cool to add a final call-to action as well, reminding people that they can comment on the RFC to help finalizing it - what do you think? |
||
|
||
|
||
--- | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We aimed to put anything that describes Ember objects, methods or similar things into code quotes (``) in the past - I think it would make sense to put any mentions of EmberObject into ``, too so, it'd become
EmberObject
.What do you think?