Skip to content

Commit e56e457

Browse files
Start converting to native classes (#671)
* Start converting to native classes * Fix lint
1 parent 7fa76e7 commit e56e457

File tree

13 files changed

+412
-153
lines changed

13 files changed

+412
-153
lines changed

addon/components/docs-code-highlight/component.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import classic from 'ember-classic-decorator';
2+
import { classNameBindings, tagName, layout as templateLayout } from '@ember-decorators/component';
13
import Component from '@ember/component';
24
import layout from './template';
35
import hljs from 'highlight.js/lib/core';
@@ -27,13 +29,14 @@ hljs.registerLanguage('sh', shell);
2729
hljs.registerLanguage('typescript', typescript);
2830
hljs.registerLanguage('ts', typescript);
2931

30-
export default Component.extend({
31-
tagName: 'pre',
32-
classNameBindings: ['language'],
33-
layout,
32+
@classic
33+
@tagName('pre')
34+
@classNameBindings('language')
35+
@templateLayout(layout)
36+
export default class DocsCodeHighlight extends Component {
3437
didInsertElement() {
35-
this._super.apply(this, arguments);
38+
super.didInsertElement(...arguments);
3639

3740
hljs.highlightBlock(this.element);
3841
}
39-
});
42+
}

addon/components/docs-demo/component.js

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { computed } from '@ember/object';
1+
import classic from 'ember-classic-decorator';
2+
import { tagName, layout as templateLayout } from '@ember-decorators/component';
3+
import { action, computed } from '@ember/object';
24
import { A } from '@ember/array';
35
import Component from '@ember/component';
46
import layout from './template';
@@ -27,23 +29,23 @@ import layout from './template';
2729
@yield {Component} demo.snippet
2830
@yield {Component} demo.liveExample
2931
*/
30-
export default Component.extend({
31-
layout,
32-
tagName: '',
33-
32+
@classic
33+
@templateLayout(layout)
34+
@tagName('')
35+
export default class DocsDemo extends Component {
3436
init() {
35-
this._super(...arguments);
37+
super.init(...arguments);
3638

3739
this.set('snippetRegistrations', A());
38-
},
40+
}
3941

4042
/**
4143
The snippets registered with this demo component
4244
4345
@field snippetRegistrations
4446
@type Array<Object>
4547
*/
46-
snippetRegistrations: null,
48+
snippetRegistrations = null;
4749

4850
/**
4951
The finalized snippets complete with name (or default), language,
@@ -54,7 +56,8 @@ export default Component.extend({
5456
@type Array<Object>
5557
@readOnly
5658
*/
57-
snippets: computed('activeSnippet', 'snippetRegistrations.[]', function() {
59+
@computed('activeSnippet', 'snippetRegistrations.[]')
60+
get snippets() {
5861
let activeSnippet = this.activeSnippet;
5962

6063
return this.snippetRegistrations
@@ -67,7 +70,7 @@ export default Component.extend({
6770
language: language || defaults.language
6871
};
6972
})
70-
}),
73+
}
7174

7275
/**
7376
Returns the default label and language based on snippet file name
@@ -102,32 +105,32 @@ export default Component.extend({
102105
}
103106

104107
return { label, language };
105-
},
106-
107-
actions: {
108-
/**
109-
Registers snippets with the demo component and sets it to the active
110-
snippet if it's the only one
111-
112-
@action registerSnippet
113-
@param {Object} snippet
114-
*/
115-
registerSnippet(snippet) {
116-
this.snippetRegistrations.pushObject(snippet);
117-
118-
if (this.get('snippetRegistrations.length') === 1) {
119-
this.set('activeSnippet', snippet.name);
120-
}
121-
},
122-
123-
/**
124-
Sets the active snippet
125-
126-
@action selectSnippet
127-
@param {Object} snippet
128-
*/
129-
selectSnippet(snippet) {
108+
}
109+
110+
/**
111+
Registers snippets with the demo component and sets it to the active
112+
snippet if it's the only one
113+
114+
@action registerSnippet
115+
@param {Object} snippet
116+
*/
117+
@action
118+
registerSnippet(snippet) {
119+
this.snippetRegistrations.pushObject(snippet);
120+
121+
if (this.get('snippetRegistrations.length') === 1) {
130122
this.set('activeSnippet', snippet.name);
131123
}
132124
}
133-
});
125+
126+
/**
127+
Sets the active snippet
128+
129+
@action selectSnippet
130+
@param {Object} snippet
131+
*/
132+
@action
133+
selectSnippet(snippet) {
134+
this.set('activeSnippet', snippet.name);
135+
}
136+
}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import classic from 'ember-classic-decorator';
2+
import { classNames, layout as templateLayout } from '@ember-decorators/component';
13
import Component from '@ember/component';
24
import layout from './template';
35

4-
export default Component.extend({
5-
layout,
6-
7-
classNames: 'docs-p-4',
8-
6+
@classic
7+
@templateLayout(layout)
8+
@classNames('docs-p-4')
9+
export default class XExample extends Component {
910
init() {
10-
this._super(...arguments);
11+
super.init(...arguments);
1112
this.set('elementId', 'example-' + this.name);
1213
}
13-
});
14+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import classic from 'ember-classic-decorator';
2+
import { classNames } from '@ember-decorators/component';
13
import LinkComponent from '@ember/routing/link-component';
24

35
/**
@@ -10,8 +12,6 @@ import LinkComponent from '@ember/routing/link-component';
1012
@class DocsLink
1113
@public
1214
*/
13-
export default LinkComponent.extend({
14-
15-
classNames: 'docs-md__a'
16-
17-
});
15+
@classic
16+
@classNames('docs-md__a')
17+
export default class DocsLink extends LinkComponent {}
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import classic from 'ember-classic-decorator';
2+
import { tagName, layout as templateLayout } from '@ember-decorators/component';
13
import { equal } from '@ember/object/computed';
24
import { assert } from '@ember/debug';
35
import Component from '@ember/component';
@@ -9,10 +11,10 @@ import layout from './template';
911
@class DocsLogo
1012
@public
1113
*/
12-
export default Component.extend({
13-
layout,
14-
tagName: '',
15-
14+
@classic
15+
@templateLayout(layout)
16+
@tagName('')
17+
export default class DocsLogo extends Component {
1618
/**
1719
Render either the 'ember', 'ember-cli' or 'ember-data' logo:
1820
@@ -25,17 +27,22 @@ export default Component.extend({
2527
@argument logo
2628
@type String
2729
*/
28-
logo: 'ember',
30+
logo = 'ember';
2931

3032
didReceiveAttrs() {
31-
this._super(...arguments);
33+
super.didReceiveAttrs(...arguments);
3234

3335
let logo = this.logo;
3436
let validLogos = ['ember', 'ember-cli', 'ember-data'];
3537
assert(`You passed "${logo}" to the docs-logo component, but the only valid options are [${validLogos}].`, validLogos.includes(logo));
36-
},
38+
}
39+
40+
@equal('logo', 'ember')
41+
showEmber;
42+
43+
@equal('logo', 'ember-cli')
44+
showEmberCli;
3745

38-
showEmber: equal('logo', 'ember'),
39-
showEmberCli: equal('logo', 'ember-cli'),
40-
showEmberData: equal('logo', 'ember-data')
41-
});
46+
@equal('logo', 'ember-data')
47+
showEmberData;
48+
}
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import classic from 'ember-classic-decorator';
2+
import { tagName, layout as templateLayout } from '@ember-decorators/component';
13
import Component from '@ember/component';
24
import layout from './template';
35

@@ -11,47 +13,47 @@ import layout from './template';
1113
@class DocsSnippet
1214
@public
1315
*/
14-
export default Component.extend({
15-
tagName: '',
16-
layout,
17-
16+
@classic
17+
@tagName('')
18+
@templateLayout(layout)
19+
export default class DocsSnippet extends Component {
1820
/**
1921
The name of the snippet
2022
2123
@argument name
2224
@type String?
2325
*/
24-
name: null,
26+
name = null;
2527

2628
/**
2729
The language of the snippet
2830
2931
@argument language
3032
@type String?
3133
*/
32-
language: null,
34+
language = null;
3335

3436
/**
3537
The title of the snippet
3638
3739
@argument title
3840
@type String?
3941
*/
40-
title: null,
42+
title = null;
4143

4244
/**
4345
Whether or not to show the copy button for this snippet
4446
4547
@argument showCopy
4648
@type Boolean
4749
*/
48-
showCopy: true,
50+
showCopy = true;
4951

5052
/**
5153
Whether or not the snippet should be unindented
5254
5355
@argument unindent
5456
@type Boolean
5557
*/
56-
unindent: true,
57-
});
58+
unindent = true;
59+
}

addon/components/docs-viewer/x-autogenerated-api-docs/component.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import Component from '@ember/component';
2-
import { inject as service } from '@ember/service';
1+
import classic from 'ember-classic-decorator';
2+
import { tagName, layout as templateLayout } from '@ember-decorators/component';
33
import { computed } from '@ember/object';
4-
import layout from './template';
4+
import { inject as service } from '@ember/service';
55
import { readOnly } from '@ember/object/computed';
6+
import Component from '@ember/component';
7+
import layout from './template';
68
import { set as _set } from 'lodash';
79

8-
export default Component.extend({
9-
layout,
10-
tagName: '',
11-
store: service(),
10+
@classic
11+
@templateLayout(layout)
12+
@tagName('')
13+
export default class XAutogeneratedApiDocs extends Component {
14+
@service
15+
store;
1216

13-
sections: readOnly('project.navigationIndex'),
17+
@readOnly('project.navigationIndex')
18+
sections;
1419

1520
/*
1621
Autogenerated sections include "resolved types", by which we mean things like
@@ -19,9 +24,10 @@ export default Component.extend({
1924
2025
These are the sections for the resolved types.
2126
*/
22-
resolvedTypeSections: computed('sections', function() {
27+
@computed('sections')
28+
get resolvedTypeSections() {
2329
return this.sections.filter(section => section.type !== 'modules');
24-
}),
30+
}
2531

2632
/*
2733
Autogenerated sections include "resolved types", by which we mean things like
@@ -57,7 +63,8 @@ export default Component.extend({
5763
};
5864
```
5965
*/
60-
moduleIndex: computed('sections', function() {
66+
@computed('sections')
67+
get moduleIndex() {
6168
let modulesSection = this.sections.filter(section => section.type === 'modules')[0];
6269

6370
if (modulesSection) {
@@ -101,6 +108,7 @@ export default Component.extend({
101108

102109
return transform(index)[0];
103110
}
104-
})
105111

106-
});
112+
return null;
113+
}
114+
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import classic from 'ember-classic-decorator';
2+
import { tagName, layout as templateLayout } from '@ember-decorators/component';
13
import Component from '@ember/component';
24
import layout from './template';
35

46
/*
57
A component used to recursively render a nested structure of module nodes.
68
*/
7-
export default Component.extend({
8-
layout,
9-
tagName: ''
10-
});
9+
@classic
10+
@templateLayout(layout)
11+
@tagName('')
12+
export default class ModuleNav extends Component {}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
import classic from 'ember-classic-decorator';
2+
import { tagName, layout as templateLayout } from '@ember-decorators/component';
13
import Component from '@ember/component';
24
import layout from './template';
35

4-
export default Component.extend({
5-
6-
layout,
7-
8-
tagName: '',
9-
10-
});
6+
@classic
7+
@templateLayout(layout)
8+
@tagName('')
9+
export default class XCurrentPageIndex extends Component {}

0 commit comments

Comments
 (0)