Skip to content

Commit d727472

Browse files
committed
partial fix and test for #276
1 parent 3d69b8c commit d727472

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

can-component.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ function getSetupFunctionForComponentVM(componentInitVM) {
206206
onCompleteBindings.push(canBinding.start.bind(canBinding));
207207

208208
// We’ll want to turn off the bindings when the component is destroyed
209-
onTeardowns.push(canBinding.stop);
209+
onTeardowns.push(canBinding.stop.bind(canBinding));
210210

211211
} else {
212212
// Can’t get or set the value, so assume it’s not an observable
@@ -590,7 +590,7 @@ var Component = Construct.extend(
590590

591591
// This adds support for components being rendered as values in stache templates
592592
Component.prototype[viewInsertSymbol] = function(viewData) {
593-
viewData.nodeList.newDeepChildren.push(this.nodeList);
593+
viewData.nodeList.deepChildren.push(this.nodeList);
594594
return this.element;
595595
};
596596

test/component-instantiation-test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ var QUnit = require("steal-qunit");
44
var SimpleMap = require("can-simple-map");
55
var stache = require("can-stache");
66
var value = require("can-value");
7+
var SimpleObservable = require("can-simple-observable");
8+
var stache = require("can-stache");
79

810
QUnit.module("can-component instantiation");
911

@@ -286,3 +288,33 @@ QUnit.test("Component binding instantiation works as documented", function() {
286288
QUnit.equal(family.get("first"), "Milo", "map “from” prop is correct");
287289
QUnit.equal(family.get("full"), "Milo Flanders", "map “to” prop is correct");
288290
});
291+
292+
QUnit.test("Component can be removed from the page", function(){
293+
var ToBeRemoved = Component.extend({
294+
tag: "to-be-removed",
295+
view: "{{prop}}",
296+
ViewModel: {
297+
prop: "string"
298+
}
299+
});
300+
301+
var prop = new SimpleObservable(3);
302+
303+
var toBeRemoved = new ToBeRemoved({
304+
viewModel: {
305+
prop: prop
306+
}
307+
});
308+
309+
var show = new SimpleObservable(true);
310+
311+
var template = stache("<div>{{# if(show) }} {{{toBeRemoved}}} {{/ if}}</div>");
312+
313+
template({
314+
show: show,
315+
toBeRemoved: toBeRemoved
316+
});
317+
318+
show.set(false);
319+
QUnit.ok(true, "got here without an error");
320+
});

0 commit comments

Comments
 (0)