KO components receives a reference of observable when we passes it as params. As componentes receives it as a reference you can write to this observable and it will reflect on your viewmodel; But, when you using ko-es5 plugin (super awesome) your KO component instead of receive also a reference to your observable receives some kind of computeObservable, and we cant write to it. is this a unexpected behaviour ?
try it using only knockout
http://jsfiddle.net/kapuca/k0fw8w18/
<voting params="votes: votes"></voting>
<template id="voting-tpl">
<button data-bind="click: increment ">Up</button>
<div data-bind="text: votes"></div>
</template>
ko.components.register('voting', {
viewModel: function(params) {
var self = this;
self.votes = params.votes;
self.increment = function(){
self.votes( self.votes() + 1 );
};
return self;
},
template: { element: 'voting-tpl' }
});
function Vm(){
this.votes = ko.observable(5);
return this;
}
ko.applyBindings(new Vm() );
try it using knockout + ko-es5 plugin
http://jsfiddle.net/kapuca/jwea6zaL/
<voting params="votes: votes"></voting>
<template id="voting-tpl">
<button data-bind="click: increment ">Up</button>
<div data-bind="text: votes"></div>
</template>
ko.components.register('voting', {
viewModel: function(params) {
var self = this;
self.votes = params.votes;
self.increment = function(){
self.votes( self.votes + 1 );
};
return ko.track(self);
},
template: { element: 'voting-tpl' }
});
function Vm(){
this.votes = 5;
return ko.track(this);
}
ko.applyBindings(new Vm() );