Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back the render hook with a pushable buffer #11012

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/ember-htmlbars/lib/system/component-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import setProperties from "ember-metal/set_properties";
import View from "ember-views/views/view";
import { MUTABLE_CELL } from "ember-views/compat/attrs-proxy";
import getCellOrValue from "ember-htmlbars/hooks/get-cell-or-value";
import SafeString from "htmlbars-util/safe-string";

// In theory this should come through the env, but it should
// be safe to import this until we make the hook system public
Expand Down Expand Up @@ -105,6 +106,20 @@ ComponentNode.prototype.render = function(env, attrs, visitor) {

if (component) {
var element = this.expectElement && this.renderNode.firstNode;
if (component.render) {
var content, node, lastChildIndex;
var buffer = [];
component.render(buffer);
content = buffer.join('');
if (element) {
lastChildIndex = this.renderNode.childNodes.length - 1;
node = this.renderNode.childNodes[lastChildIndex];
} else {
node = this.renderNode;
}
node.setContent(new SafeString(content));
}

env.renderer.didCreateElement(component, element); // 2.0TODO: Remove legacy hooks.
env.renderer.willInsertElement(component, element);
env.lifecycleHooks.push({ type: 'didInsertElement', view: component });
Expand Down
34 changes: 1 addition & 33 deletions packages/ember-htmlbars/lib/system/render-view.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
import Ember from "ember-metal/core";
import defaultEnv from "ember-htmlbars/env";
import { get } from "ember-metal/property_get";
import ComponentNode, { createOrUpdateComponent } from "ember-htmlbars/system/component-node";

export default function renderView(view, buffer, template) {
if (!template) {
return;
}

var output;

Ember.assert('template must be a function. Did you mean to call Ember.Handlebars.compile("...") or specify templateName instead?', typeof template === 'function');
output = renderLegacyTemplate(view, buffer, template);

if (output !== undefined) {
buffer.push(output);
}
}

// This function only gets called once per render of a "root view" (`appendTo`). Otherwise,
// HTMLBars propagates the existing env and renders templates for a given render node.
export function renderHTMLBarsBlock(view, block, renderNode) {
Expand All @@ -36,22 +19,7 @@ export function renderHTMLBarsBlock(view, block, renderNode) {

view.env = env;
createOrUpdateComponent(view, {}, renderNode, env);
var componentNode = new ComponentNode(view, null, renderNode, block, true);
var componentNode = new ComponentNode(view, null, renderNode, block, view.tagName !== '');

componentNode.render(env, {});
}

function renderLegacyTemplate(view, buffer, template) {
// FIXME: This should likely be removed. Adds support for bespoke kind-of-handlebars
// templates. They are used in tests, but nobody should be using them in the
// wild.
var context = get(view, 'context');
var options = {
data: {
view: view,
buffer: buffer
}
};

return template(context, options);
}
Loading