Skip to content

Commit

Permalink
Merge pull request canjs#2115 from prashantsharmain/master
Browse files Browse the repository at this point in the history
%root property is serialized when can.Map instance is shared between a component viewModel and a can.route
  • Loading branch information
daffl committed Dec 7, 2015
2 parents 5ab0b1f + c6f07e8 commit e405976
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions component/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ steal("can/util", "can/view/callbacks","can/view/elements.js","can/view/bindings
viewModel = new(can.Map.extend(scopeResult))(initialViewModelData);
}
}

var oldSerialize = viewModel.serialize;
viewModel.serialize = function () {
var result = oldSerialize.apply(this, arguments);
delete result["%root"];
return result;
};

return viewModel;
}, initialViewModelData));
Expand Down
20 changes: 18 additions & 2 deletions component/component_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,23 @@ steal("can-simple-dom", "can/util/vdom/build_fragment","can", "can/map/define",
passedProp: "value"
});
});


test("%root property should not be serialized inside prototype of can.Component constructor (#2080)", function () {
var viewModel = can.Map.extend({});

can.Component.extend({
tag: "foo",
viewModel: viewModel,
init: function () {
ok(!this.viewModel.serialize()['%root'], "serialized viewModel contains '%root' property");
}
});

var template = can.stache("<foo/>");

can.append(this.$fixture, template());
});

// PUT NEW TESTS ABOVE THIS LINE
}

Expand Down Expand Up @@ -1828,4 +1844,4 @@ steal("can-simple-dom", "can/util/vdom/build_fragment","can", "can/map/define",
});

// DONT PUT TESTS HERE!!! Look up for where to put new tests.
});
});

0 comments on commit e405976

Please sign in to comment.