Skip to content

Commit

Permalink
Merge pull request #99 from salsify/fare-thee-well-resolver-monkeypat…
Browse files Browse the repository at this point in the history
…ching

Fare thee well, resolver monkeypatching
  • Loading branch information
dfreeman authored Jun 13, 2018
2 parents 22b6f71 + e779359 commit 6733e77
Show file tree
Hide file tree
Showing 20 changed files with 668 additions and 1,425 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
language: node_js
node_js:
- "4"
- "6"

sudo: true
dist: trusty
Expand Down
10 changes: 0 additions & 10 deletions addon/extensions.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import Controller from '@ember/controller';
import Component from '@ember/component';
import Ember from 'ember';
import Resolver from 'ember-resolver';

import ComponentMixin from './mixins/component-mixin';
import ControllerMixin from './mixins/controller-mixin';
import ComponentLookupMixin from './mixins/component-lookup-mixin';
import ResolverMixin from './mixins/resolver-mixin';

Component.reopen(ComponentMixin);
Controller.reopen(ControllerMixin);
Ember.ComponentLookup.reopen(ComponentLookupMixin);
Resolver.reopen(ResolverMixin);
30 changes: 0 additions & 30 deletions addon/mixins/component-lookup-mixin.js

This file was deleted.

26 changes: 20 additions & 6 deletions addon/mixins/component-mixin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* global require */

import { computed, defineProperty } from '@ember/object';
import Mixin from '@ember/object/mixin';
import { dasherize } from '@ember/string';
import { getOwner } from '@ember/application';
import { assert } from '@ember/debug';

export default Mixin.create({
localClassNames: null,
Expand All @@ -27,18 +30,29 @@ export default Mixin.create({
},

__styles__: computed(function() {
// If styles is an explicitly set hash, defer to it. Otherwise, use the resolver.
if (this.styles && Object.getPrototypeOf(this.styles) === Object.prototype) {
return this.styles;
}

let key = this._debugContainerKey;
if (!key) { return; }

return getOwner(this).resolveRegistration(`styles:components/${key.substring(key.indexOf(':') + 1)}`);
let name = key.replace(/^component:/, '');
let layout = this.layout || getOwner(this).lookup(`template:components/${name}`);
assert('Unable to resolve localClassNames or localClassNameBindings for a component with no layout', layout);

// This is not public API and might break at any time...
let moduleName = (layout.meta || layout.referrer).moduleName.replace(/\.hbs$/, '');
if (/\/template$/.test(moduleName)) {
return tryLoad(moduleName.replace(/template$/, 'styles'));
} else if (/\/templates\//.test(moduleName)) {
return tryLoad(moduleName.replace('/templates/', '/styles/'));
}
})
});

function tryLoad(path) {
if (require.has(path)) {
return require(path).default;
}
}

const LOCAL_CLASS_NAMES_CP = '__ecm_local_class_names__';

function localClassNames(component) {
Expand Down
17 changes: 0 additions & 17 deletions addon/mixins/controller-mixin.js

This file was deleted.

18 changes: 0 additions & 18 deletions addon/mixins/resolver-mixin.js

This file was deleted.

2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
install:
- ps: Install-Product node 4
- ps: Install-Product node 6
- yarn

cache:
Expand Down
20 changes: 1 addition & 19 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict';

const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
const Funnel = require('broccoli-funnel');
const path = require('path');

const HAS_EMBER_SOURCE = 'ember-source' in require('./package.json').devDependencies;

module.exports = function(defaults) {
let app = new EmberAddon(defaults, {
Expand Down Expand Up @@ -37,19 +33,5 @@ module.exports = function(defaults) {
}
});

if (app.env === 'test') {
app.import(`${HAS_EMBER_SOURCE ? 'vendor' : 'bower_components'}/ember/ember-template-compiler.js`);
}

let additionalTrees = [];

if (HAS_EMBER_SOURCE) {
additionalTrees.push(new Funnel(path.dirname(require.resolve('ember-source')), {
srcDir: 'dist',
destDir: 'vendor/ember',
include: ['ember-template-compiler.js']
}));
}

return app.toTree(additionalTrees);
return app.toTree();
};
Loading

0 comments on commit 6733e77

Please sign in to comment.