I registered my views(html) and my viewModel(js) as knockout components. In my main file(index.html), I data-bind the components to show the different views. At this time when I want to quick debug a viewModel in the html with ko.toJSON($data, null,2), I need to add the data-bindin for ko.toJSON in everey html file which I want to debug. I would like to have a more generic way to do this like data-bind the ko.toJSON only in the main file(index-html) and pass the viewModel/$data?? to it.
//index.html
<body>
//here I want a generic way to debug my app like:
// <div data-bind="?">
<div id="page" data-bind="component: {name: viewModel}"></div>
</body>
// components
ko.components.register('home', ko_home.init );
ko.components.register('import', ko_import.init );
//view
<main>
<h1>home</h1>
<div data-bind="text: greeting"></div>
// here I put the binding for debug in every view. It should be removed and //placed in the index.html
<pre data-bind="text: ko.toJson($data, null,2)"></pre>
</main>
//viewModel
const fs = require('fs');
const template = fs.readFileSync(__dirname + '/home.html', 'utf8');
function Home() {
this.greeting = ko.observable('Hello');
}
exports.init = { viewModel: Home, template: template };