Skip to content

Commit

Permalink
Merge pull request #360 from canjs/logStack-newComponent-mutation
Browse files Browse the repository at this point in the history
logStack include component instantiation mutations
  • Loading branch information
cherifGsoul authored Sep 17, 2019
2 parents ad8428b + 89aacb0 commit a0e2139
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions can-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,19 @@ var Component = Construct.extend(
} else if (componentTagData.viewModel) {
// Component is being instantiated with a viewModel
setupFn = getSetupFunctionForComponentVM(componentTagData.viewModel);

//!steal-remove-start
if (process.env.NODE_ENV !== 'production') {
setupFn = queues.runAsTask(setupFn, function(el, componentTagData) {
return ["Constructing", el, "with viewModel",componentTagData.viewModel];
});
}
//!steal-remove-end
} else {
setupFn = stacheBindings.behaviors.viewModel;
}


teardownBindings = setupFn(el, componentTagData, function(initialViewModelData) {

var ViewModel = component.constructor.ViewModel,
Expand Down
22 changes: 22 additions & 0 deletions test/component-can-bind-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var helpers = require("./helpers");
var QUnit = require("steal-qunit");
var SimpleMap = require("can-simple-map");
var value = require("can-value");
var queues = require("can-queues");
var testHelpers = require("can-test-helpers");

QUnit.module("can-component integration with can-bind");

Expand Down Expand Up @@ -70,3 +72,23 @@ QUnit.test("Using can-bind in connectedCallback works as documented", function(a
done();
});
});

testHelpers.dev.devOnlyTest("logStack should include `new Component()` mutations", function(assert) {
var ComponentConstructor = Component.extend({
tag: "a-tag",
view: '{{foo}}',
ViewModel: {
setup: function () {
var expected = queues.stack().length > 0;
assert.ok(expected, "At least one task on the stack");
},
foo: 'string'
}
});

new ComponentConstructor({
viewModel : {
foo: "bar"
}
});
});

0 comments on commit a0e2139

Please sign in to comment.