JSFiddle - React, Tailwind, and code Playground
HTML
<div id="bindMeLikeOneOfYourFrenchLadies">
<div>Object notifications <span data-bind="text: objectNotifications"></span></div>
<div>Text notifications <span data-bind="text: textNotifications"></span></div>
<button data-bind="click: breakMeUpMrScott">Clean it</button>
</div>
JavaScript
function TestVm () {
var self = this;
self.testObject = ko.observable({});
self.objectNotifications = ko.observable(0);
self.testObject.subscribe(function () {
var val = self.objectNotifications();
self.objectNotifications(val + 1);
});
self.testText = ko.observable("So long, and thanks for the fish!");
self.textNotifications = ko.observable(0);
self.testText.subscribe(function () {
var val = self.textNotifications();
self.textNotifications(val + 1);
});
self.breakMeUpMrScott = function () {
var currentObj = self.testObject(),
currentText = self.testText();
self.testObject(currentObj);
self.testText(currentText);
}
}
var vm = new TestVm(),
target = document.getElementById("bindMeLikeOneOfYourFrenchLadies");
ko.applyBindings(vm, target);