Skip to content

Commit 27ab46a

Browse files
committed
Rework JavaScript->Python traitlet message properties.
Setting to null on JS side was causing some dropped messages. The goal is for all of the messages to arrive, but not remain in the traitlet for embdedding.
1 parent a126ddd commit 27ab46a

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

js/src/Figure.js

-6
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,6 @@ var FigureView = widgets.DOMWidgetView.extend({
10271027

10281028
this.model.set("_js2py_restyle", restyleMsg);
10291029
this.touch();
1030-
this.model.set("_js2py_restyle", null);
10311030
},
10321031

10331032
/**
@@ -1058,7 +1057,6 @@ var FigureView = widgets.DOMWidgetView.extend({
10581057

10591058
this.model.set("_js2py_relayout", relayoutMsg);
10601059
this.touch();
1061-
this.model.set("_js2py_relayout", null);
10621060
},
10631061

10641062
/**
@@ -1092,7 +1090,6 @@ var FigureView = widgets.DOMWidgetView.extend({
10921090

10931091
this.model.set("_js2py_update", updateMsg);
10941092
this.touch();
1095-
this.model.set("_js2py_update", null);
10961093
},
10971094

10981095
/**
@@ -1157,7 +1154,6 @@ var FigureView = widgets.DOMWidgetView.extend({
11571154

11581155
this.model.set("_js2py_pointsCallback", pointsMsg);
11591156
this.touch();
1160-
this.model.set("_js2py_pointsCallback", null);
11611157
}
11621158
},
11631159

@@ -1390,7 +1386,6 @@ var FigureView = widgets.DOMWidgetView.extend({
13901386

13911387
this.model.set("_js2py_layoutDelta", layoutDeltaMsg);
13921388
this.touch();
1393-
this.model.set("_js2py_layoutDelta", null);
13941389
},
13951390

13961391
/**
@@ -1422,7 +1417,6 @@ var FigureView = widgets.DOMWidgetView.extend({
14221417
console.log(["traceDeltasMsg", traceDeltasMsg]);
14231418
this.model.set("_js2py_traceDeltas", traceDeltasMsg);
14241419
this.touch();
1425-
this.model.set("_js2py_traceDeltas", null);
14261420
}
14271421
});
14281422

plotly/basewidget.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,8 @@ def _handler_js2py_traceDeltas(self, change):
451451
# Receive message
452452
# ---------------
453453
msg_data = change['new']
454-
self._js2py_traceDeltas = None
455454
if not msg_data:
455+
self._js2py_traceDeltas = None
456456
return
457457

458458
trace_deltas = msg_data['trace_deltas']
@@ -504,6 +504,8 @@ def _handler_js2py_traceDeltas(self, change):
504504
while self._waiting_edit_callbacks:
505505
self._waiting_edit_callbacks.pop()()
506506

507+
self._js2py_traceDeltas = None
508+
507509
@observe('_js2py_layoutDelta')
508510
def _handler_js2py_layoutDelta(self, change):
509511
"""
@@ -513,8 +515,8 @@ def _handler_js2py_layoutDelta(self, change):
513515
# Receive message
514516
# ---------------
515517
msg_data = change['new']
516-
self._js2py_layoutDelta = None
517518
if not msg_data:
519+
self._js2py_layoutDelta = None
518520
return
519521

520522
layout_delta = msg_data['layout_delta']
@@ -566,6 +568,8 @@ def _handler_js2py_layoutDelta(self, change):
566568
while self._waiting_edit_callbacks:
567569
self._waiting_edit_callbacks.pop()()
568570

571+
self._js2py_layoutDelta = None
572+
569573
@observe('_js2py_restyle')
570574
def _handler_js2py_restyle(self, change):
571575
"""
@@ -575,8 +579,9 @@ def _handler_js2py_restyle(self, change):
575579
# Receive message
576580
# ---------------
577581
restyle_msg = change['new']
578-
self._js2py_restyle = None
582+
579583
if not restyle_msg:
584+
self._js2py_restyle = None
580585
return
581586

582587
style_data = restyle_msg['style_data']
@@ -589,6 +594,8 @@ def _handler_js2py_restyle(self, change):
589594
trace_indexes=style_traces,
590595
source_view_id=source_view_id)
591596

597+
self._js2py_restyle = None
598+
592599
@observe('_js2py_update')
593600
def _handler_js2py_update(self, change):
594601
"""
@@ -598,8 +605,9 @@ def _handler_js2py_update(self, change):
598605
# Receive message
599606
# ---------------
600607
update_msg = change['new']
601-
self._js2py_update = None
608+
602609
if not update_msg:
610+
self._js2py_update = None
603611
return
604612

605613
style = update_msg['style_data']
@@ -613,6 +621,8 @@ def _handler_js2py_update(self, change):
613621
trace_indexes=trace_indexes,
614622
source_view_id=source_view_id)
615623

624+
self._js2py_update = None
625+
616626
@observe('_js2py_relayout')
617627
def _handler_js2py_relayout(self, change):
618628
"""
@@ -622,8 +632,9 @@ def _handler_js2py_relayout(self, change):
622632
# Receive message
623633
# ---------------
624634
relayout_msg = change['new']
625-
self._js2py_relayout = None
635+
626636
if not relayout_msg:
637+
self._js2py_relayout = None
627638
return
628639

629640
relayout_data = relayout_msg['relayout_data']
@@ -640,6 +651,8 @@ def _handler_js2py_relayout(self, change):
640651
self.plotly_relayout(relayout_data=relayout_data,
641652
source_view_id=source_view_id)
642653

654+
self._js2py_relayout = None
655+
643656
@observe('_js2py_pointsCallback')
644657
def _handler_js2py_pointsCallback(self, change):
645658
"""
@@ -649,8 +662,9 @@ def _handler_js2py_pointsCallback(self, change):
649662
# Receive message
650663
# ---------------
651664
callback_data = change['new']
652-
self._js2py_pointsCallback = None
665+
653666
if not callback_data:
667+
self._js2py_pointsCallback = None
654668
return
655669

656670
# Get event type
@@ -718,6 +732,8 @@ def _handler_js2py_pointsCallback(self, change):
718732
elif event_type == 'plotly_selected':
719733
trace._dispatch_on_selection(points, selector)
720734

735+
self._js2py_pointsCallback = None
736+
721737
# Callbacks
722738
# ---------
723739
def on_edits_completed(self, fn):

0 commit comments

Comments
 (0)