Repository navigation
Change Tutorial examples to use Class Syntax (#540) - #551
Conversation
|
This fixes #540 |
There was a problem hiding this comment.
First pass CR. This looks really good.
Found two issues (missing constructor args and improperly calling parent method).
@classNames is a question. @jenweber ?
| classNames: ['list-filter'], | ||
| value: '', | ||
| export default class ListFilterComponent extends Component { | ||
| classNames = ['list-filter']; |
There was a problem hiding this comment.
Do we also want to use the @classNames decorator? @jenweber
There was a problem hiding this comment.
I've added them. I forgot about this decorator 😃
Co-Authored-By: muziejus <[email protected]>
Co-Authored-By: muziejus <[email protected]>
Co-Authored-By: muziejus <[email protected]>
| export default Component.extend({ | ||
| classNames: ['list-filter'], | ||
| value: '', | ||
| export default class ListFilterComponent extends Component { |
There was a problem hiding this comment.
Not to muddy the waters here too much, but I thought native class syntax should only apply to Glimmer components: https://github.com/ember-learn/guides-source/blob/octane/guides/release/upgrading/editions.md#glimmer-components. Does this seem correct?
There was a problem hiding this comment.
yes, native class syntax applies to everything except classic components. This is because we don't have first class APIs for things like classNames.
There was a problem hiding this comment.
The recent changes to the component blueprints in emberjs/ember.js to support octane were done before we had decided that we didn't want to show native class syntax with Ember.Component at all.
Would someone mind making an issue over there to get it fixed (if you cc @ppcano he will probably be willing to fix it up...)
There was a problem hiding this comment.
created that issue: emberjs/ember.js#17701
pzuraq
left a comment
There was a problem hiding this comment.
This is generally looking good. I think the last step we need to do is to convert the classic components to Glimmer components, which should be fairly straightforward (let me know if you need any help with it though!) and to remove any references to ember-decorators is favor of Ember's own first-class decorators
| export default Component.extend({ | ||
| classNames: ['list-filter'], | ||
| value: '', | ||
| export default class ListFilterComponent extends Component { |
There was a problem hiding this comment.
yes, native class syntax applies to everything except classic components. This is because we don't have first class APIs for things like classNames.
| ```javascript {data-filename=app/components/list-filter.js} | ||
| import Component from '@ember/component'; | ||
| import { action } from '@ember-decorators/object'; | ||
| import { classNames } from '@ember-decorators/component'; |
There was a problem hiding this comment.
ember-decorators is not an official Ember addon, so we aren't going to have it in any examples. Ember itself does support the following decorators:
import { computed, action } from '@ember/object';
import { inject as service } from '@ember/service';
import { inject as controller } from '@ember/controller';
import * from '@ember/object/computed';This does mean that we don't have the proper decorators to convert classic components to native class syntax, which is what the core team has agreed on. Everything except class components should always be native classes, and classic components should use classic class syntax.
There was a problem hiding this comment.
Thanks, all. I'll have a look later today and see what I can fix up.
|
Thank you @muziejus for taking this on! |
| classNames: ['list-filter'], | ||
| value: '', | ||
| export default class ListFilterComponent extends Component { | ||
| classNames = 'list-filter'; |
There was a problem hiding this comment.
So, we should actually convert this to a GlimmerComponent. You can check out the edition guide to see what the differences are. In this example, we would update the template like so:
This moves the classNames to be a part of the template, because Glimmer components don't have a wrapping element. We also remove the {{action}} helper from around the action, since it's no longer necessary (@action does the same thing). We would then update the class like this:
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
export default class ListFilterComponent extends Component {
@tracked value = '';
@tracked results;
constructor() {
super(...arguments);
this.args.filter('').then((results) => this.results = results);
}
@action
handleFilterEntry() {
let filterInputValue = this.value;
let filterAction = this.args.filter;
filterAction(filterInputValue).then((filterResults) => this.results = filterResults);
}
}Here we're importing from @glimmer/component instead of @ember/component, which is the new base class. We also have to use this.args to refer to arguments because of this, so we have to update this.filter to this.args.filter in general. Finally, Glimmer components don't have this.set, so we either have to use Ember.set, or convert to tracked props. I went for the latter here.
This PR is really looking great, thanks for being understanding, I know there are a lot of changes and they're hard to work through and not all that transparent yet. This is going to be very helpful in getting all this info out there 😄
There was a problem hiding this comment.
Oh this is great. Thanks. I understand perfectly now, I think. And I'm glad for the clarity about wrapping tags, too, since I'm sick of dealing w/ classNames and tagNames in my component.jses anyway.
|
OK, between @pzuraq's responses and what @efx did for the component blueprint in emberjs, I think I've got a general sense of what the goals are here:
|
|
@pzuraq Pinging you again. I think I've gotten it, and I caught a few overzealous mistakes from elsewhere. |
|
Awesome job, thanks again for this! |
Ember Data blueprints will also use Native syntax, check out the open PR warp-drive-data/warp-drive#5859 |
@jamescdavis