JSFiddle - React, Tailwind, and code Playground

by rniemeyer

HTML

<script src="http://knockoutjs.com/downloads/knockout-3.1.0.debug.js"></script>

JavaScript

//a few observables to work with
var test = ko.observable("one"),
    test2 = ko.observable("two"),
    test3 = ko.observable("three");


//start tracking dependencies and receive a notification when anything observable is accessed
ko.dependencyDetection.begin({
    callback: function(subscribable, internalId) {
        console.log("original context: " + internalId + " was accessed");  
    }
});

//access an observable
test();

//output: 
//original context: 1 was accessed

    //start another dependency detection inside of the current one
    ko.dependencyDetection.begin({
        callback: function(subscribable, internalId) {
            console.log("    child context: " + internalId + " was accessed"); 
        }
    });
    
    //inside of child context again access test and also test2
    test();
    test2();
     
    //output
    //child context: 1 was accessed
    //child context: 2 was accessed


    //end child context
    ko.dependencyDetection.end();

test3();

//output
//original context: 3 was accessed

//end original context
ko.dependencyDetection.end();