Skip to content

Commit

Permalink
fix(module imports): moved functionality that belonged to just the ad…
Browse files Browse the repository at this point in the history
…don, over to the addon. fix #259
  • Loading branch information
webark committed Feb 6, 2018
1 parent d37adb1 commit c016731
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 93 deletions.
63 changes: 63 additions & 0 deletions addon/initializers/component-styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import Ember from "ember";
import Component from '@ember/component';
import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import { getOwner } from '@ember/application';

import podNames from 'ember-component-css/pod-names';

const {
ComponentLookup,
} = Ember;

ComponentLookup.reopen({
componentFor(name, owner) {
owner = owner.hasRegistration ? owner : getOwner(this);

if (podNames[name] && !owner.hasRegistration(`component:${name}`)) {
owner.register(`component:${name}`, Component);
}
return this._super(...arguments);
},
});

Component.reopen({
_componentIdentifier: computed({
get() {
return (this._debugContainerKey || '').replace('component:', '');
}
}),

_shouldAddNamespacedClassName: computed({
get() {
return this.get('tagName') !== '' && this.get('styleNamespace');
}
}),

styleNamespace: computed({
get() {
return podNames[this.get('_componentIdentifier')] || '';
}
}),

// componentCssClassName: deprecatingAlias('styleNamespace', {
// id: 'ember-component-css.deprecate-componentCssClassName',
// until: '0.7.0',
// }),

componentCssClassName: alias('styleNamespace'),

init() {
this._super(...arguments);

if (this.get('_shouldAddNamespacedClassName')) {
this.classNames = this.classNames.concat(this.get('styleNamespace'));
}
},
});

export function initialize() {}

export default {
initialize
};
29 changes: 29 additions & 0 deletions addon/initializers/route-styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Router from '@ember/routing/router';
import { getOwner } from '@ember/application';

import podNames from 'ember-component-css/pod-names';

Router.reopen({
didTransition(routes) {
this._super(...arguments);

const classes = [];
for (let i = 0; i < routes.length; i++) {
let route = routes[i];
let currentPath = route.name.replace(/\./g, '/');

if (podNames[currentPath]) {
getOwner(this).lookup(`controller:${route.name}`).set('styleNamespace', podNames[currentPath]);
classes.push(podNames[currentPath]);
}
}

getOwner(this).lookup('controller:application').set('routeStyleNamespaceClassSet', classes.join(' '));
}
});

export function initialize() {}

export default {
initialize
};
15 changes: 1 addition & 14 deletions addon/mixins/style-namespacing-extras.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
import Mixin from '@ember/object/mixin';
import { computed } from '@ember/object';

export default Mixin.create({
_componentIdentifier: computed({
get() {
return (this._debugContainerKey || '').replace('component:', '');
}
}),

_shouldAddNamespacedClassName: computed({
get() {
return this.get('tagName') !== '' && this.get('styleNamespace');
}
}),
});
export default Mixin.create();
55 changes: 5 additions & 50 deletions app/initializers/component-styles.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,8 @@
import Ember from "ember";
import Component from '@ember/component';
import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import { getOwner } from '@ember/application';
export { default, initialize } from 'ember-component-css/initializers/component-styles';

import podNames from 'ember-component-css/pod-names';
import StyleNamespacingExtras from '../mixins/style-namespacing-extras';

const {
ComponentLookup,
} = Ember;

ComponentLookup.reopen({
componentFor(name, owner) {
owner = owner.hasRegistration ? owner : getOwner(this);

if (podNames[name] && !owner.hasRegistration(`component:${name}`)) {
owner.register(`component:${name}`, Component);
}
return this._super(...arguments);
}
});

Component.reopen(StyleNamespacingExtras, {
styleNamespace: computed({
get() {
return podNames[this.get('_componentIdentifier')] || '';
}
}),
import Ember from 'ember';

// componentCssClassName: deprecatingAlias('styleNamespace', {
// id: 'ember-component-css.deprecate-componentCssClassName',
// until: '0.7.0',
// }),

componentCssClassName: alias('styleNamespace'),

init() {
this._super(...arguments);

if (this.get('_shouldAddNamespacedClassName')) {
this.classNames = this.classNames.concat(this.get('styleNamespace'));
}
}
});

export function initialize() {}
import StyleNamespacingExtras from '../mixins/style-namespacing-extras';

export default {
name: 'component-styles',
initialize
};
// eslint-disable-next-line ember/new-module-imports
Ember.Component.reopen(StyleNamespacingExtras);
30 changes: 1 addition & 29 deletions app/initializers/route-styles.js
Original file line number Diff line number Diff line change
@@ -1,29 +1 @@
import Router from '@ember/routing/router';
import { getOwner } from '@ember/application';
import podNames from 'ember-component-css/pod-names';

Router.reopen({
didTransition(routes) {
this._super(...arguments);

const classes = [];
for (let i = 0; i < routes.length; i++) {
let route = routes[i];
let currentPath = route.name.replace(/\./g, '/');

if (podNames[currentPath]) {
getOwner(this).lookup(`controller:${route.name}`).set('styleNamespace', podNames[currentPath]);
classes.push(podNames[currentPath]);
}
}

getOwner(this).lookup('controller:application').set('routeStyleNamespaceClassSet', classes.join(' '));
}
});

export function initialize() {}

export default {
name: 'route-styles',
initialize
};
export { default, initialize } from 'ember-component-css/initializers/route-styles';

0 comments on commit c016731

Please sign in to comment.