Skip to content

Commit

Permalink
slashed components rendering and ignore issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeart committed Oct 8, 2018
1 parent 96dedb4 commit 3f31e6e
Show file tree
Hide file tree
Showing 23 changed files with 161 additions and 6 deletions.
11 changes: 6 additions & 5 deletions addon/mixins/hot-reload-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const TEMPLATE_MATCH_REGEX = new RegExp(/-original$/);
function removeOriginalFromParsedName (parsedName, pattern) {
parsedName.fullName = parsedName.fullName.replace(pattern, '');
parsedName.fullNameWithoutType = parsedName.fullNameWithoutType.replace(pattern, '');
parsedName.name= parsedName.name.replace(pattern, '');
parsedName.name = parsedName.name.replace(pattern, '');
}

function shouldIgnoreTemplate (parsedName, pattern) {
Expand All @@ -36,14 +36,15 @@ export default Mixin.create({
resolveOther(parsedName) {
captureTemplateOptions(parsedName);
const templateMatchRegex = get(this, 'originalTemplateMatchRegex');
const resolved = this._super(...arguments);

if (parsedName.type === 'template' && shouldIgnoreTemplate(parsedName, templateMatchRegex)) {
return;
return resolved;
}

const resolved = this._super(...arguments);

if (parsedName.type === 'component') {
if (this.shouldExcludeComponent(parsedName)) {
return this._super(parsedName);
return resolved;
}
if (resolved) {
return this._resolveComponent(resolved, parsedName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Component from '@ember/component';
import hbs from 'htmlbars-inline-precompile';

export default Component.extend({
layout: hbs`
<p>Inline slashed pod component rendering test <span>{{myName}}</span><button>{{myName}}</button></p>
`,
myName: 'excluded-slashed-pod/inline-template'
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Component from '@ember/component';

export default Component.extend({
tagName: 'div',
classNames: ['excluded-slashed-pod__js-only'],
didRender() {
this.element.innerHTML = '<button>excluded- JS-only component</button>';
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Component from '@ember/component';
import layout from './template';

export default Component.extend({
layout
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{yield}}
<button>This is excluded-slashed-pod/mixed-classic component</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button>This is excluded-slashed-pod/template-only component</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Component from '@ember/component';
import hbs from 'htmlbars-inline-precompile';

export default Component.extend({
layout: hbs`
<p>Inline slashed component rendering test <span>{{myName}}</span> <button>{{myName}}</button></p>
`,
myName: 'excluded-slashed/inline-template'
});
8 changes: 8 additions & 0 deletions tests/dummy/app/components/excluded-slashed/js-only.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Component from '@ember/component';
export default Component.extend({
tagName: 'div',
classNames: ['excluded-slashed__js-only'],
didRender() {
this.element.innerHTML = '<button>JS-only component</button>';
}
});
6 changes: 6 additions & 0 deletions tests/dummy/app/components/excluded-slashed/mixed-classic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Component from '@ember/component';
import layout from '../../templates/components/slashed/mixed-classic';

export default Component.extend({
layout
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Component from '@ember/component';
import hbs from 'htmlbars-inline-precompile';

export default Component.extend({
layout: hbs`
<p>Inline slashed pod component rendering test <span>{{myName}}</span><button>{{myName}}</button></p>
`,
myName: 'slashed-pod/inline-template'
});
9 changes: 9 additions & 0 deletions tests/dummy/app/components/slashed-pod/js-only/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Component from '@ember/component';

export default Component.extend({
tagName: 'div',
classNames: ['slashed-pod__js-only'],
didRender() {
this.element.innerHTML = '<button>JS-only component</button>';
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Component from '@ember/component';
import layout from './template';

export default Component.extend({
layout
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{yield}}
<button>This is slashed-pod/mixed-classic component</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button>This is slashed-pod/template-only component</button>
9 changes: 9 additions & 0 deletions tests/dummy/app/components/slashed/inline-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Component from '@ember/component';
import hbs from 'htmlbars-inline-precompile';

export default Component.extend({
layout: hbs`
<p>Inline slashed component rendering test <span>{{myName}}</span> <button>{{myName}}</button></p>
`,
myName: 'slashed/inline-template'
});
8 changes: 8 additions & 0 deletions tests/dummy/app/components/slashed/js-only.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Component from '@ember/component';
export default Component.extend({
tagName: 'div',
classNames: ['slashed-pod__js-only'],
didRender() {
this.element.innerHTML = '<button>JS-only component</button>';
}
});
6 changes: 6 additions & 0 deletions tests/dummy/app/components/slashed/mixed-classic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Component from '@ember/component';
import layout from '../../templates/components/slashed/mixed-classic';

export default Component.extend({
layout
});
11 changes: 10 additions & 1 deletion tests/dummy/app/resolver.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import Resolver from 'ember-resolver';
import HotReloadMixin from 'ember-cli-hot-loader/mixins/hot-reload-resolver';
import Mixin from '@ember/object/mixin';

export default Resolver.extend(HotReloadMixin);
const CustomHotReloadMixin = Mixin.create(HotReloadMixin, {
shouldExcludeComponent({name}) {
const excludedFromConfig = this._super(...arguments);
const isSlashedComponent = name.startsWith('excluded-slashed');
return excludedFromConfig || isSlashedComponent;
}
});

export default Resolver.extend(CustomHotReloadMixin);
37 changes: 37 additions & 0 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,40 @@ JS Only pod: {{js-only-pod}}
{{dom-evented classNames="dom-evented"}}
<h2>component-with-actions using classic actions (not supported atm)</h2>
{{component-with-actions classNames="component-with-actions--classic" componentAction="routeAction"}}

<h2>slashed js-only component rendering test</h2>
{{slashed/js-only}}
<h2>slashed template-only component rendering test</h2>
{{slashed/template-only}}
<h2>slashed inline-template component rendering test</h2>
{{slashed/inline-template}}
<h2>slashed mixed-classic component rendering test</h2>
{{slashed/mixed-classic}}

<h2>slashed podded js-only component rendering test</h2>
{{slashed-pod/js-only}}
<h2>slashed podded template-only component rendering test</h2>
{{slashed-pod/template-only}}
<h2>slashed podded inline-template component rendering test</h2>
{{slashed-pod/inline-template}}
<h2>slashed podded mixed-classic component rendering test</h2>
{{slashed-pod/mixed-classic}}

<h2>excluded-slashed js-only component rendering test</h2>
{{#excluded-slashed/js-only}}1{{/excluded-slashed/js-only}}
<h2>excluded-slashed template-only component rendering test</h2>
{{excluded-slashed/template-only}}
<h2>excluded-slashed inline-template component rendering test</h2>
{{excluded-slashed/inline-template}}
<h2>excluded-slashed mixed-classic component rendering test</h2>
{{excluded-slashed/mixed-classic}}


<h2>excluded-slashed podded js-only component rendering test</h2>
{{excluded-slashed-pod/js-only}}
<h2>excluded-slashed podded template-only component rendering test</h2>
{{excluded-slashed-pod/template-only}}
<h2>excluded-slashed podded inline-template component rendering test</h2>
{{excluded-slashed-pod/inline-template}}
<h2>excluded-slashed podded mixed-classic component rendering test</h2>
{{excluded-slashed-pod/mixed-classic}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{yield}}
<button>This is excluded-slashed/mixed-classic component</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{yield}}
<button>This is excluded-slashed/template-only component</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{yield}}
<button>This is slashed/mixed-classic component</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{yield}}
<button>This is slashed/template-only component</button>

0 comments on commit 3f31e6e

Please sign in to comment.