Skip to content

Commit

Permalink
[FEATURE ember-glimmer-remove-application-template-wrapper]
Browse files Browse the repository at this point in the history
Implement RFC emberjs/rfcs#280
  • Loading branch information
chancancode committed Dec 14, 2017
1 parent 37ceda1 commit cb77ef9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 24 deletions.
5 changes: 5 additions & 0 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ for a detailed explanation.
Add `{{@foo}}` syntax to access named arguments in component templates per
[RFC](https://github.com/emberjs/rfcs/pull/276).

* `ember-glimmer-remove-application-template-wrapper`

Remvoe the `<div>` wrapper around the application template per
[RFC](https://github.com/emberjs/rfcs/pull/280).

* `ember-glimmer-template-only-components`

Use Glimmer Components semantics for template-only components per
Expand Down
1 change: 1 addition & 0 deletions features.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"ember-libraries-isregistered": null,
"ember-improved-instrumentation": null,
"ember-glimmer-named-arguments": null,
"ember-glimmer-remove-application-template-wrapper": null,
"ember-glimmer-template-only-components": null,
"ember-routing-router-service": true,
"ember-engines-mount-params": true,
Expand Down
1 change: 1 addition & 0 deletions packages/ember-glimmer/externs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ declare module 'ember/features' {
export const GLIMMER_CUSTOM_COMPONENT_MANAGER: boolean | null;
export const EMBER_ENGINES_MOUNT_PARAMS: boolean | null;
export const EMBER_GLIMMER_DETECT_BACKTRACKING_RERENDER: boolean | null;
export const EMBER_GLIMMER_REMOVE_APPLICATION_TEMPLATE_WRAPPER: boolean | null;
export const EMBER_GLIMMER_TEMPLATE_ONLY_COMPONENTS: boolean | null;
export const MANDATORY_SETTER: boolean | null;
}
Expand Down
50 changes: 28 additions & 22 deletions packages/ember-glimmer/lib/component-managers/outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Destroyable } from '@glimmer/util/dist/types';
import { DEBUG } from 'ember-env-flags';
import { _instrumentStart } from 'ember-metal';
import { generateGuid, guidFor } from 'ember-utils';
import { EMBER_GLIMMER_REMOVE_APPLICATION_TEMPLATE_WRAPPER } from 'ember/features';
import EmberEnvironment from '../environment';
import {
OwnedTemplate,
Expand Down Expand Up @@ -92,13 +93,35 @@ class TopLevelOutletComponentManager extends OutletComponentManager {
}
return new StateBucket(dynamicScope.outletState.value());
}

layoutFor(definition: OutletComponentDefinition, _bucket: StateBucket, env: Environment) {
return (env as EmberEnvironment).getCompiledBlock(TopLevelOutletLayoutCompiler, definition.template);
}
}

const TOP_LEVEL_MANAGER = new TopLevelOutletComponentManager();
const TOP_LEVEL_MANAGER = (() => {
if (EMBER_GLIMMER_REMOVE_APPLICATION_TEMPLATE_WRAPPER) {
return new TopLevelOutletComponentManager();
} else {
class WrappedTopLevelOutletLayoutCompiler {
static id = 'wrapped-top-level-outlet';

constructor(public template: WrappedTemplateFactory) {
}

compile(builder: any) {
builder.wrapLayout(this.template);
builder.tag.static('div');
builder.attrs.static('id', guidFor(this));
builder.attrs.static('class', 'ember-view');
}
}

class WrappedTopLevelOutletComponentManager extends TopLevelOutletComponentManager {
layoutFor(definition: OutletComponentDefinition, _bucket: StateBucket, env: Environment) {
return (env as EmberEnvironment).getCompiledBlock(WrappedTopLevelOutletLayoutCompiler, definition.template);
}
}

return new WrappedTopLevelOutletComponentManager();
}
})();

export class TopLevelOutletComponentDefinition extends ComponentDefinition<StateBucket> {
public template: WrappedTemplateFactory;
Expand All @@ -109,23 +132,6 @@ export class TopLevelOutletComponentDefinition extends ComponentDefinition<State
}
}

class TopLevelOutletLayoutCompiler {
static id: string;
public template: WrappedTemplateFactory;
constructor(template: WrappedTemplateFactory) {
this.template = template;
}

compile(builder: any) {
builder.wrapLayout(this.template);
builder.tag.static('div');
builder.attrs.static('id', guidFor(this));
builder.attrs.static('class', 'ember-view');
}
}

TopLevelOutletLayoutCompiler.id = 'top-level-outlet';

export class OutletComponentDefinition extends ComponentDefinition<StateBucket> {
public outletName: string;
public template: OwnedTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ import { Component } from 'ember-glimmer';

moduleFor('Application test: rendering', class extends ApplicationTest {

['@test it can render the application template'](assert) {
['@feature(!ember-glimmer-remove-application-template-wrapper) it can render the application template'](assert) {
this.addTemplate('application', 'Hello world!');

return this.visit('/').then(() => {
this.assertText('Hello world!');
this.assertComponentElement(this.firstChild, { content: 'Hello world!' });
});
}

['@feature(ember-glimmer-remove-application-template-wrapper) it can render the application template'](assert) {
this.addTemplate('application', 'Hello world!');

return this.visit('/').then(() => {
this.assertHTML('Hello world!');
});
}

Expand Down

0 comments on commit cb77ef9

Please sign in to comment.