Skip to content

Commit e3c627b

Browse files
committed
feat(extensable identifier): moved the geration of the namespace identifier and if the class should be added to a mixin for easier exensability
1 parent 24d03ef commit e3c627b

File tree

4 files changed

+66
-52
lines changed

4 files changed

+66
-52
lines changed
Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +0,0 @@
1-
import Ember from 'ember';
2-
import podNames from 'ember-component-css/pod-names';
3-
4-
const {
5-
Component,
6-
ComponentLookup,
7-
computed,
8-
getOwner
9-
} = Ember;
10-
11-
ComponentLookup.reopen({
12-
componentFor(name, owner) {
13-
owner = owner.hasRegistration ? owner : getOwner(this);
14-
15-
if (podNames[name] && !owner.hasRegistration(`component:${name}`)) {
16-
owner.register(`component:${name}`, Component);
17-
}
18-
return this._super(...arguments);
19-
}
20-
});
21-
22-
Component.reopen({
23-
_componentIdentifier: computed({
24-
get() {
25-
return (this._debugContainerKey || '').replace('component:', '');
26-
}
27-
}),
28-
29-
componentCssClassName: computed({
30-
get() {
31-
return podNames[this.get('_componentIdentifier')] || '';
32-
}
33-
}),
34-
35-
init() {
36-
this._super(...arguments);
37-
38-
let name = this.get('componentCssClassName');
39-
40-
if (this.get('tagName') !== '' && name) {
41-
this.classNames = this.classNames.concat(name);
42-
}
43-
}
44-
});
45-
46-
export function initialize() {}
47-
48-
export default {
49-
name: 'component-styles',
50-
initialize
51-
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Ember from 'ember';
2+
3+
const {
4+
Component,
5+
computed,
6+
Mixin,
7+
} = Ember;
8+
9+
export default Mixin.create({
10+
_componentIdentifier: computed({
11+
get() {
12+
return (this._debugContainerKey || '').replace('component:', '');
13+
}
14+
}),
15+
16+
_shouldAddNamespacedClassName: computed({
17+
get() {
18+
return this.get('tagName') !== '' && this.get('componentCssClassName');
19+
}
20+
}),
21+
});

app/initializers/component-styles.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,44 @@
1-
export { default, initialize } from 'ember-component-css/initializers/component-styles';
1+
import Ember from 'ember';
2+
import podNames from 'ember-component-css/pod-names';
3+
import StyleNamespacingExtras from '../mixins/style-namespacing-extras';
4+
5+
const {
6+
Component,
7+
ComponentLookup,
8+
computed,
9+
getOwner
10+
} = Ember;
11+
12+
ComponentLookup.reopen({
13+
componentFor(name, owner) {
14+
owner = owner.hasRegistration ? owner : getOwner(this);
15+
16+
if (podNames[name] && !owner.hasRegistration(`component:${name}`)) {
17+
owner.register(`component:${name}`, Component);
18+
}
19+
return this._super(...arguments);
20+
}
21+
});
22+
23+
Component.reopen(StyleNamespacingExtras, {
24+
componentCssClassName: computed({
25+
get() {
26+
return podNames[this.get('_componentIdentifier')] || '';
27+
}
28+
}),
29+
30+
init() {
31+
this._super(...arguments);
32+
33+
if (this.get('_shouldAddNamespacedClassName')) {
34+
this.classNames = this.classNames.concat(this.get('componentCssClassName'));
35+
}
36+
}
37+
});
38+
39+
export function initialize() {}
40+
41+
export default {
42+
name: 'component-styles',
43+
initialize
44+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from 'ember-component-css/mixins/style-namespacing-extras';

0 commit comments

Comments
 (0)