I have a simple model, and on there is an observable ("model.thing"). I then set an additional observable on this ("someProp") and pass it into the params of a component.
model.thing = ko.observable({});
model.thing.someProp = ko.observable("Yolo");
At this point the observable has become a computed and i'm not sure why.
If i change the model so that instead of having model.thing
as an observable i have it as a simple object and then pass that in, it is coming through without changing into a computed...
Does anyone have an explanation for this behaviour?
Here's a working example (it alerts the param which shows that it has become a computed).
var viewModel = function() {
var model = {};
model.thing = ko.observable({}); //when thing is observable
//model.thing = {};
model.thing.someProp = ko.observable("Yolo");
return model;
};
ko.components.register('custom-element', {
viewModel: function(params) {
this.value = params.value;
alert(this.value); //then this is dependent, why?!
},
template:
'<div data-bind="text: value"></div>'
});
ko.applyBindings(viewModel);
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/knockout.mapping/2.4.1/knockout.mapping.js"></script>
<title>Knockout component</title>
</head>
<body>
<custom-element params="value: thing().someProp"></custom-element>
<!--
<custom-element params="value: thing.someProp"></custom-element> -->
</body>
</html>