JSFiddle - React, Tailwind, and code Playground

by fastfasterfastest

HTML

<script src="https://unpkg.com/[email protected]/build/output/knockout-latest.debug.js"></script>
<input type="checkbox" data-bind="checked: checked">

<span data-bind="text: checked"></span>

JavaScript

function observableBoolean(value, confirm){
	var observable,
  	_value = !!value;
  
  observable = ko.pureComputed({
  	read: function() {
    	console.log("read() => " + _value);
    	return _value;
    },
    write: function(v){
    	console.log("write(" + v + ")");
    	if(v !== _value){
      	_value = confirm(v) ? !!v : !v;
     		console.log("calling notifySubscribers(" + _value + ")");
        debugger;
        	observable.notifySubscribers(_value);
      }
    }
  });
  
  
	return observable;  
}
var checked = observableBoolean(false, function(newValue){
	return confirm('Are you sure you want to ' + (newValue ? 'check' : 'uncheck') + ' it?');
});

ko.applyBindings({ checked: checked })