@jupyterlab/services
Advanced tools
Comparing version 0.45.0 to 0.46.0
@@ -298,2 +298,8 @@ import { IDisposable } from '@phosphor/disposable'; | ||
/** | ||
* Handle a message with a display id. | ||
* | ||
* @returns Whether the message was handled. | ||
*/ | ||
private _handleDisplayId(displayId, msg); | ||
/** | ||
* Handle a websocket close event. | ||
@@ -355,2 +361,4 @@ */ | ||
private _unhandledMessage; | ||
private _displayIdToParentIds; | ||
private _msgIdToDisplayIds; | ||
} | ||
@@ -357,0 +365,0 @@ /** |
@@ -61,2 +61,4 @@ "use strict"; | ||
this._unhandledMessage = new signaling_1.Signal(this); | ||
this._displayIdToParentIds = new Map(); | ||
this._msgIdToDisplayIds = new Map(); | ||
this._name = options.name; | ||
@@ -247,2 +249,4 @@ this._id = id; | ||
}); | ||
this._displayIdToParentIds.clear(); | ||
this._msgIdToDisplayIds.clear(); | ||
this._futures = null; | ||
@@ -287,3 +291,26 @@ this._commPromises = null; | ||
var future = new future_1.KernelFutureHandler(function () { | ||
_this._futures.delete(msg.header.msg_id); | ||
var msgId = msg.header.msg_id; | ||
_this._futures.delete(msgId); | ||
// Remove stored display id information. | ||
var displayIds = _this._msgIdToDisplayIds.get(msgId); | ||
if (!displayIds) { | ||
return; | ||
} | ||
displayIds.forEach(function (displayId) { | ||
var msgIds = _this._displayIdToParentIds.get(displayId); | ||
if (msgIds) { | ||
var idx = msgIds.indexOf(msgId); | ||
if (idx === -1) { | ||
return; | ||
} | ||
if (msgIds.length === 1) { | ||
_this._displayIdToParentIds.delete(displayId); | ||
} | ||
else { | ||
msgIds.splice(idx, 1); | ||
_this._displayIdToParentIds.set(displayId, msgIds); | ||
} | ||
} | ||
}); | ||
_this._msgIdToDisplayIds.delete(msgId); | ||
}, msg, expectReply, disposeOnDone, this); | ||
@@ -677,3 +704,20 @@ this._futures.set(msg.header.msg_id, future); | ||
} | ||
if (msg.parent_header) { | ||
var handled = false; | ||
if (msg.parent_header && msg.channel === 'iopub') { | ||
switch (msg.header.msg_type) { | ||
case 'display_data': | ||
case 'update_display_data': | ||
case 'execute_result': | ||
// display_data messages may re-route based on their display_id. | ||
var transient = (msg.content.transient || {}); | ||
var displayId = transient['display_id']; | ||
if (displayId) { | ||
handled = this._handleDisplayId(displayId, msg); | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
if (!handled && msg.parent_header) { | ||
var parentHeader = msg.parent_header; | ||
@@ -713,2 +757,51 @@ var future = this._futures && this._futures.get(parentHeader.msg_id); | ||
/** | ||
* Handle a message with a display id. | ||
* | ||
* @returns Whether the message was handled. | ||
*/ | ||
DefaultKernel.prototype._handleDisplayId = function (displayId, msg) { | ||
var _this = this; | ||
var msgId = msg.parent_header.msg_id; | ||
var parentIds = this._displayIdToParentIds.get(displayId); | ||
if (parentIds) { | ||
// We've seen it before, update existing outputs with same display_id | ||
// by handling display_data as update_display_data. | ||
var updateMsg_1 = { | ||
header: coreutils_2.JSONExt.deepCopy(msg.header), | ||
parent_header: coreutils_2.JSONExt.deepCopy(msg.parent_header), | ||
metadata: coreutils_2.JSONExt.deepCopy(msg.metadata), | ||
content: coreutils_2.JSONExt.deepCopy(msg.content), | ||
channel: msg.channel, | ||
buffers: msg.buffers ? msg.buffers.slice() : [] | ||
}; | ||
updateMsg_1.header.msg_type = 'update_display_data'; | ||
parentIds.map(function (parentId) { | ||
var future = _this._futures && _this._futures.get(parentId); | ||
if (future) { | ||
future.handleMsg(updateMsg_1); | ||
} | ||
}); | ||
} | ||
// We're done here if it's update_display. | ||
if (msg.header.msg_type === 'update_display_data') { | ||
// It's an update, don't proceed to the normal display. | ||
return true; | ||
} | ||
// Regular display_data with id, record it for future updating | ||
// in _displayIdToParentIds for future lookup. | ||
parentIds = this._displayIdToParentIds.get(displayId) || []; | ||
if (parentIds.indexOf(msgId) === -1) { | ||
parentIds.push(msgId); | ||
} | ||
this._displayIdToParentIds.set(displayId, parentIds); | ||
// Add to our map of display ids for this message. | ||
var displayIds = this._msgIdToDisplayIds.get(msgId) || []; | ||
if (displayIds.indexOf(msgId) === -1) { | ||
displayIds.push(msgId); | ||
} | ||
this._msgIdToDisplayIds.set(msgId, displayIds); | ||
// Let it propagate to the intended recipient. | ||
return false; | ||
}; | ||
/** | ||
* Handle a websocket close event. | ||
@@ -805,2 +898,4 @@ */ | ||
this._comms = new Map(); | ||
this._displayIdToParentIds.clear(); | ||
this._msgIdToDisplayIds.clear(); | ||
}; | ||
@@ -807,0 +902,0 @@ /** |
@@ -21,3 +21,3 @@ "use strict"; | ||
username: options.username || '', | ||
version: '5.0', | ||
version: '5.2', | ||
session: options.session, | ||
@@ -24,0 +24,0 @@ msg_id: options.msgId || coreutils_1.uuid(), |
{ | ||
"name": "@jupyterlab/services", | ||
"version": "0.45.0", | ||
"version": "0.46.0", | ||
"description": "Client APIs for the Jupyter services REST APIs", | ||
@@ -8,7 +8,7 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@jupyterlab/coreutils": "^0.6.0", | ||
"@phosphor/algorithm": "^1.1.0", | ||
"@phosphor/coreutils": "^1.1.0", | ||
"@phosphor/disposable": "^1.1.0", | ||
"@phosphor/signaling": "^1.2.0", | ||
"@jupyterlab/coreutils": "^0.7.0", | ||
"@phosphor/algorithm": "^1.1.1", | ||
"@phosphor/coreutils": "^1.1.1", | ||
"@phosphor/disposable": "^1.1.1", | ||
"@phosphor/signaling": "^1.2.1", | ||
"@types/text-encoding": "0.0.30" | ||
@@ -15,0 +15,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
371926
10669
+ Added@jupyterlab/coreutils@0.7.1(transitive)
- Removed@jupyterlab/coreutils@0.6.0(transitive)
Updated@jupyterlab/coreutils@^0.7.0
Updated@phosphor/algorithm@^1.1.1
Updated@phosphor/coreutils@^1.1.1
Updated@phosphor/disposable@^1.1.1
Updated@phosphor/signaling@^1.2.1