mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Make deprecated use of UI.render/UI.insert work
(but warn)
This commit is contained in:
@@ -459,10 +459,8 @@ var contentAsFunc = function (content) {
|
||||
|
||||
Blaze.render = function (content, parentElement, nextNode, parentView) {
|
||||
if (! parentElement) {
|
||||
// This is a deprecation error (UI.render used to take one arg)
|
||||
// XXX make this work for back-compat
|
||||
throw new Error(
|
||||
"render requires a DOM element to insert the rendered content into");
|
||||
Blaze._warn("Blaze.render without a parent element is deprecated. " +
|
||||
"You must specify where to insert the rendered content.");
|
||||
}
|
||||
|
||||
if (nextNode instanceof Blaze.View) {
|
||||
@@ -474,7 +472,7 @@ Blaze.render = function (content, parentElement, nextNode, parentView) {
|
||||
// parentElement must be a DOM node. in particular, can't be the
|
||||
// result of a call to `$`. Can't check if `parentElement instanceof
|
||||
// Node` since 'Node' is undefined in IE8.
|
||||
if (typeof parentElement.nodeType !== 'number')
|
||||
if (parentElement && typeof parentElement.nodeType !== 'number')
|
||||
throw new Error("'parentElement' must be a DOM node");
|
||||
if (nextNode && typeof nextNode.nodeType !== 'number') // 'nextNode' is optional
|
||||
throw new Error("'nextNode' must be a DOM node");
|
||||
@@ -484,15 +482,21 @@ Blaze.render = function (content, parentElement, nextNode, parentView) {
|
||||
var view = contentAsView(content);
|
||||
Blaze._materializeView(view, parentView);
|
||||
|
||||
view._domrange.attach(parentElement, nextNode);
|
||||
if (parentElement) {
|
||||
view._domrange.attach(parentElement, nextNode);
|
||||
}
|
||||
|
||||
return view;
|
||||
};
|
||||
|
||||
Blaze.insert = function () {
|
||||
// Deprecation error
|
||||
throw new Error("Blaze.insert has been deprecated. Specify where to insert the " +
|
||||
"rendered content in Blaze.render.");
|
||||
Blaze.insert = function (view, parentElement, nextNode) {
|
||||
Blaze._warn("Blaze.insert has been deprecated. Specify where to insert the " +
|
||||
"rendered content in the call to Blaze.render.");
|
||||
|
||||
if (! (view && (view._domrange instanceof Blaze._DOMRange)))
|
||||
throw new Error("Expected template rendered with UI.render");
|
||||
|
||||
view._domrange.attach(parentElement, nextNode);
|
||||
};
|
||||
|
||||
Blaze.renderWithData = function (content, data, parentElement, nextNode, parentView) {
|
||||
|
||||
@@ -2379,10 +2379,6 @@ Tinytest.add(
|
||||
var x = UI.render(tmpl, otherDiv);
|
||||
// note: we'll have clean up `x` below
|
||||
|
||||
test.throws(function () {
|
||||
UI.render(tmpl); // no second argument
|
||||
});
|
||||
|
||||
var renderedTmpl2 = UI.renderWithData(
|
||||
tmpl, {greeting: 'Bye'}, div);
|
||||
test.equal(canonicalizeHtml(div.innerHTML),
|
||||
|
||||
Reference in New Issue
Block a user