Skip to content

Commit

Permalink
comm flow working
Browse files Browse the repository at this point in the history
  • Loading branch information
timkpaine committed Jan 30, 2018
1 parent b686229 commit a47cb75
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions packages/perspective-jupyterlab/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,40 +61,37 @@ class RenderedPSP extends Widget implements IRenderMime.IRenderer {
//grab session id
let els = this.datasrc.replace('comm://', '').split('/');
let kernelId = els[0];
let target = els[1];

Session.listRunning().then(sessionModels => {
for(let i=0; i<sessionModels.length; i++){
console.log(sessionModels[i]);
if(sessionModels[i].kernel.id === kernelId){
Session.connectTo(sessionModels[i]).then((session) => {
session.kernel.registerCommTarget(target, (comm: any, commMsg:any) => {
if (commMsg.content.target_name !== target) {
return;
}

comm.onMsg = (msg: any) => {
console.log(msg); // 'hello'
let dat = msg['content']['data'];
let tmp = JSON.parse(dat);
tmp = [
{'x': 1, 'y':'a', 'z': true},
{'x': 2, 'y':'b', 'z': false},
{'x': 3, 'y':'c', 'z': true},
{'x': 4, 'y':'d', 'z': false}
];
psp.load(tmp);
};
comm.onClose = (msg: any) => {
console.log(msg); // 'bye'
};
});

let comm = session.kernel.connectToComm('lantern.live');
comm.open('test');
comm.onMsg = (msg: any) => {
console.log(msg); // 'hello'
let dat = msg['content']['data'];
let tmp = JSON.parse(dat);
tmp = [
{'x': 1, 'y':'a', 'z': true},
{'x': 2, 'y':'b', 'z': false},
{'x': 3, 'y':'c', 'z': true},
{'x': 4, 'y':'d', 'z': false}
];

psp.update(tmp);
};
comm.onClose = (msg: any) => {
console.log(msg); // 'bye'
};

});
}
}
});
}
this._loaded = true;
}

renderModel(model: IRenderMime.IMimeModel): Promise<void> {
Expand Down

0 comments on commit a47cb75

Please sign in to comment.