Skip to content

Commit

Permalink
Merge pull request #19229 from sanji11/issue-18060
Browse files Browse the repository at this point in the history
[CLEANUP] Remove the EMBER_GLIMMER_SET_COMPONENT_TEMPLATE flag
  • Loading branch information
Chris Garrett authored Oct 26, 2020
2 parents 1b08b25 + 93ee224 commit dce6d62
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 167 deletions.
20 changes: 6 additions & 14 deletions packages/@ember/-internals/glimmer/lib/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { privatize as P } from '@ember/-internals/container';
import { ENV } from '@ember/-internals/environment';
import { Factory, FactoryClass, LookupOptions, Owner } from '@ember/-internals/owner';
import { OwnedTemplateMeta } from '@ember/-internals/views';
import {
EMBER_GLIMMER_HELPER_MANAGER,
EMBER_GLIMMER_SET_COMPONENT_TEMPLATE,
} from '@ember/canary-features';
import { EMBER_GLIMMER_HELPER_MANAGER } from '@ember/canary-features';
import { isTemplateOnlyComponent } from '@ember/component/template-only';
import { assert, deprecate } from '@ember/debug';
import { PARTIALS } from '@ember/deprecated-features';
Expand Down Expand Up @@ -106,13 +103,11 @@ function lookupComponentPair(
): Option<LookupResult> {
let component = componentFor(name, owner, options);

if (EMBER_GLIMMER_SET_COMPONENT_TEMPLATE) {
if (component !== null && component.class !== undefined) {
let layout = getComponentTemplate(component.class);
if (component !== null && component.class !== undefined) {
let layout = getComponentTemplate(component.class);

if (layout !== null) {
return { component, layout };
}
if (layout !== null) {
return { component, layout };
}
}

Expand Down Expand Up @@ -462,10 +457,7 @@ export default class RuntimeResolverImpl implements RuntimeResolver<OwnedTemplat
if (ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS) {
definition = new TemplateOnlyComponentDefinition(name, layout!);
}
} else if (
EMBER_GLIMMER_SET_COMPONENT_TEMPLATE &&
isTemplateOnlyComponent(pair.component.class)
) {
} else if (isTemplateOnlyComponent(pair.component.class)) {
definition = new TemplateOnlyComponentDefinition(name, layout!);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,138 +1,135 @@
import { moduleFor, RenderingTestCase, runTask } from 'internal-test-helpers';

import { EMBER_GLIMMER_SET_COMPONENT_TEMPLATE } from '@ember/canary-features';
import { HAS_NATIVE_SYMBOL } from '@ember/-internals/utils';

import { Component, compile } from '../../utils/helpers';
import { setComponentTemplate, getComponentTemplate } from '../../..';

if (EMBER_GLIMMER_SET_COMPONENT_TEMPLATE) {
moduleFor(
'Components test: setComponentTemplate',
class extends RenderingTestCase {
'@test it basically works'() {
this.registerComponent('foo-bar', {
ComponentClass: setComponentTemplate(compile('hello'), Component.extend()),
});
moduleFor(
'Components test: setComponentTemplate',
class extends RenderingTestCase {
'@test it basically works'() {
this.registerComponent('foo-bar', {
ComponentClass: setComponentTemplate(compile('hello'), Component.extend()),
});

this.render('<FooBar />');
this.render('<FooBar />');

this.assertComponentElement(this.firstChild, { content: 'hello' });
this.assertComponentElement(this.firstChild, { content: 'hello' });

runTask(() => this.rerender());
runTask(() => this.rerender());

this.assertComponentElement(this.firstChild, { content: 'hello' });
}
this.assertComponentElement(this.firstChild, { content: 'hello' });
}

'@test it takes precedence over resolver'() {
this.registerComponent('foo-bar', {
ComponentClass: setComponentTemplate(compile('hello'), Component.extend()),
template: 'noooooo!',
});
'@test it takes precedence over resolver'() {
this.registerComponent('foo-bar', {
ComponentClass: setComponentTemplate(compile('hello'), Component.extend()),
template: 'noooooo!',
});

this.render('<FooBar />');
this.render('<FooBar />');

this.assertComponentElement(this.firstChild, { content: 'hello' });
this.assertComponentElement(this.firstChild, { content: 'hello' });

runTask(() => this.rerender());
runTask(() => this.rerender());

this.assertComponentElement(this.firstChild, { content: 'hello' });
}

'@test calling it with primitives asserts'() {
expectAssertion(() => {
setComponentTemplate(compile('foo'), null);
}, /Cannot call `setComponentTemplate` on `null`/);
this.assertComponentElement(this.firstChild, { content: 'hello' });
}

expectAssertion(() => {
setComponentTemplate(compile('foo'), undefined);
}, /Cannot call `setComponentTemplate` on `undefined`/);
'@test calling it with primitives asserts'() {
expectAssertion(() => {
setComponentTemplate(compile('foo'), null);
}, /Cannot call `setComponentTemplate` on `null`/);

expectAssertion(() => {
setComponentTemplate(compile('foo'), true);
}, /Cannot call `setComponentTemplate` on `true`/);
expectAssertion(() => {
setComponentTemplate(compile('foo'), undefined);
}, /Cannot call `setComponentTemplate` on `undefined`/);

expectAssertion(() => {
setComponentTemplate(compile('foo'), false);
}, /Cannot call `setComponentTemplate` on `false`/);
expectAssertion(() => {
setComponentTemplate(compile('foo'), true);
}, /Cannot call `setComponentTemplate` on `true`/);

expectAssertion(() => {
setComponentTemplate(compile('foo'), 123);
}, /Cannot call `setComponentTemplate` on `123`/);
expectAssertion(() => {
setComponentTemplate(compile('foo'), false);
}, /Cannot call `setComponentTemplate` on `false`/);

expectAssertion(() => {
setComponentTemplate(compile('foo'), 'foo');
}, /Cannot call `setComponentTemplate` on `foo`/);

if (HAS_NATIVE_SYMBOL) {
expectAssertion(() => {
setComponentTemplate(compile('foo'), Symbol('foo'));
}, /Cannot call `setComponentTemplate` on `Symbol\(foo\)`/);
}
}
expectAssertion(() => {
setComponentTemplate(compile('foo'), 123);
}, /Cannot call `setComponentTemplate` on `123`/);

'@test calling it twice on the same object asserts'() {
let Thing = setComponentTemplate(
compile('hello'),
Component.extend().reopenClass({
toString() {
return 'Thing';
},
})
);
expectAssertion(() => {
setComponentTemplate(compile('foo'), 'foo');
}, /Cannot call `setComponentTemplate` on `foo`/);

if (HAS_NATIVE_SYMBOL) {
expectAssertion(() => {
setComponentTemplate(compile('foo'), Thing);
}, /Cannot call `setComponentTemplate` multiple times on the same class \(`Thing`\)/);
setComponentTemplate(compile('foo'), Symbol('foo'));
}, /Cannot call `setComponentTemplate` on `Symbol\(foo\)`/);
}
}

'@test templates set with setComponentTemplate are inherited (EmberObject.extend())'() {
let Parent = setComponentTemplate(compile('hello'), Component.extend());
'@test calling it twice on the same object asserts'() {
let Thing = setComponentTemplate(
compile('hello'),
Component.extend().reopenClass({
toString() {
return 'Thing';
},
})
);

expectAssertion(() => {
setComponentTemplate(compile('foo'), Thing);
}, /Cannot call `setComponentTemplate` multiple times on the same class \(`Thing`\)/);
}

this.registerComponent('foo-bar', {
ComponentClass: Parent.extend(),
});
'@test templates set with setComponentTemplate are inherited (EmberObject.extend())'() {
let Parent = setComponentTemplate(compile('hello'), Component.extend());

this.render('<FooBar />');
this.registerComponent('foo-bar', {
ComponentClass: Parent.extend(),
});

this.assertComponentElement(this.firstChild, { content: 'hello' });
this.render('<FooBar />');

runTask(() => this.rerender());
this.assertComponentElement(this.firstChild, { content: 'hello' });

this.assertComponentElement(this.firstChild, { content: 'hello' });
}
runTask(() => this.rerender());

'@test templates set with setComponentTemplate are inherited (native ES class extends)'() {
let Parent = setComponentTemplate(compile('hello'), Component.extend());
this.assertComponentElement(this.firstChild, { content: 'hello' });
}

this.registerComponent('foo-bar', {
ComponentClass: class extends Parent {},
});
'@test templates set with setComponentTemplate are inherited (native ES class extends)'() {
let Parent = setComponentTemplate(compile('hello'), Component.extend());

this.render('<FooBar />');
this.registerComponent('foo-bar', {
ComponentClass: class extends Parent {},
});

this.assertComponentElement(this.firstChild, { content: 'hello' });
this.render('<FooBar />');

runTask(() => this.rerender());
this.assertComponentElement(this.firstChild, { content: 'hello' });

this.assertComponentElement(this.firstChild, { content: 'hello' });
}
runTask(() => this.rerender());

'@test it can re-assign templates from another class'() {
let Foo = setComponentTemplate(compile('shared'), Component.extend());
let Bar = setComponentTemplate(getComponentTemplate(Foo), Component.extend());
this.assertComponentElement(this.firstChild, { content: 'hello' });
}

this.registerComponent('foo', { ComponentClass: Foo });
this.registerComponent('bar', { ComponentClass: Bar });
'@test it can re-assign templates from another class'() {
let Foo = setComponentTemplate(compile('shared'), Component.extend());
let Bar = setComponentTemplate(getComponentTemplate(Foo), Component.extend());

this.render('<Foo />|<Bar />');
this.registerComponent('foo', { ComponentClass: Foo });
this.registerComponent('bar', { ComponentClass: Bar });

this.assertText('shared|shared');
this.render('<Foo />|<Bar />');

runTask(() => this.rerender());
this.assertText('shared|shared');

this.assertText('shared|shared');
}
runTask(() => this.rerender());

this.assertText('shared|shared');
}
);
}
}
);
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { moduleFor, RenderingTestCase, classes, runTask } from 'internal-test-helpers';
import { EMBER_GLIMMER_SET_COMPONENT_TEMPLATE } from '@ember/canary-features';

import { ENV } from '@ember/-internals/environment';
import { setComponentTemplate } from '@ember/-internals/glimmer';
import templateOnly from '@ember/component/template-only';
Expand Down Expand Up @@ -266,56 +264,54 @@ if (ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS) {
);
}

if (EMBER_GLIMMER_SET_COMPONENT_TEMPLATE) {
moduleFor(
'Components test: template-only components (using `templateOnlyComponent()`)',
class extends RenderingTestCase {
['@test it can render a component']() {
this.registerComponent('foo-bar', { ComponentClass: templateOnly(), template: 'hello' });
moduleFor(
'Components test: template-only components (using `templateOnlyComponent()`)',
class extends RenderingTestCase {
['@test it can render a component']() {
this.registerComponent('foo-bar', { ComponentClass: templateOnly(), template: 'hello' });

this.render('{{foo-bar}}');
this.render('{{foo-bar}}');

this.assertInnerHTML('hello');
this.assertInnerHTML('hello');

this.assertStableRerender();
}
this.assertStableRerender();
}

['@test it can render a component when template was not registered']() {
let ComponentClass = templateOnly();
setComponentTemplate(compile('hello'), ComponentClass);
['@test it can render a component when template was not registered']() {
let ComponentClass = templateOnly();
setComponentTemplate(compile('hello'), ComponentClass);

this.registerComponent('foo-bar', { ComponentClass });
this.registerComponent('foo-bar', { ComponentClass });

this.render('{{foo-bar}}');
this.render('{{foo-bar}}');

this.assertInnerHTML('hello');
this.assertInnerHTML('hello');

this.assertStableRerender();
}
this.assertStableRerender();
}

['@test setComponentTemplate takes precedence over registered layout']() {
let ComponentClass = templateOnly();
setComponentTemplate(compile('hello'), ComponentClass);
['@test setComponentTemplate takes precedence over registered layout']() {
let ComponentClass = templateOnly();
setComponentTemplate(compile('hello'), ComponentClass);

this.registerComponent('foo-bar', {
ComponentClass,
template: 'this should not be rendered',
});
this.registerComponent('foo-bar', {
ComponentClass,
template: 'this should not be rendered',
});

this.render('{{foo-bar}}');
this.render('{{foo-bar}}');

this.assertInnerHTML('hello');
this.assertInnerHTML('hello');

this.assertStableRerender();
}
this.assertStableRerender();
}

['@test templateOnly accepts a moduleName to be used for debugging / toString purposes'](
assert
) {
let ComponentClass = templateOnly('my-app/components/foo');
['@test templateOnly accepts a moduleName to be used for debugging / toString purposes'](
assert
) {
let ComponentClass = templateOnly('my-app/components/foo');

assert.equal(`${ComponentClass}`, 'my-app/components/foo');
}
assert.equal(`${ComponentClass}`, 'my-app/components/foo');
}
);
}
}
);
4 changes: 0 additions & 4 deletions packages/@ember/canary-features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const DEFAULT_FEATURES = {
EMBER_LIBRARIES_ISREGISTERED: null,
EMBER_IMPROVED_INSTRUMENTATION: null,
EMBER_NAMED_BLOCKS: null,
EMBER_GLIMMER_SET_COMPONENT_TEMPLATE: true,
EMBER_GLIMMER_HELPER_MANAGER: true,
EMBER_GLIMMER_INVOKE_HELPER: true,
EMBER_MODERNIZED_BUILT_IN_COMPONENTS: null,
Expand Down Expand Up @@ -71,9 +70,6 @@ function featureValue(value: null | boolean) {
export const EMBER_LIBRARIES_ISREGISTERED = featureValue(FEATURES.EMBER_LIBRARIES_ISREGISTERED);
export const EMBER_IMPROVED_INSTRUMENTATION = featureValue(FEATURES.EMBER_IMPROVED_INSTRUMENTATION);
export const EMBER_NAMED_BLOCKS = featureValue(FEATURES.EMBER_NAMED_BLOCKS);
export const EMBER_GLIMMER_SET_COMPONENT_TEMPLATE = featureValue(
FEATURES.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE
);
export const EMBER_GLIMMER_HELPER_MANAGER = featureValue(FEATURES.EMBER_GLIMMER_HELPER_MANAGER);
export const EMBER_GLIMMER_INVOKE_HELPER = featureValue(FEATURES.EMBER_GLIMMER_INVOKE_HELPER);
export const EMBER_MODERNIZED_BUILT_IN_COMPONENTS = featureValue(
Expand Down
Loading

0 comments on commit dce6d62

Please sign in to comment.