I need to make data which is available in the "onmessage" Callback function of WebSocket connection to a Component View Model of KnockoutJS.
sockjs.onmessage = function (e) {
//console.log('[.] message', e.data);
if(e.data && e.data.length){
var jsonData = JSON.parse(e.data);
//I need to make this jsonData available to Custom Component of knockoutJS
}
};
But the problem here is, I am not creating the instance of ViewModel in my code. I am using Custom Components of KnockoutJS and registering it through the below code
ko.components.register('bing-map', {
viewModel: { require: 'bing-maps/bing-maps' },
template: { require: 'text!bing-map/bing-map.html' }
});
My Component's View Model is as below
define(['knockout'], function(ko){
var MapViewModel = function(params){
var self = this;
self.map = {
options:{
credentials:<bing map key>
}
}
}
return MapViewModel;
});