Repository: ipython/ipython

Issue:
Problems when displaying multiple views of ContainerWidget. 
`ContainerView.render` registers anonymous functions to `this.model.on('displayed')` . This is a problem because when rendering multiple views of the same widget container, multiple instances of this anonymous function get registered to this event. 

PS: This is also related to #5958



Discussion:
Thanks for pointing this out.  You're right, this is the wrong place for this code, and it's my fault it's here.  I think it should be moved to the model somehow.  I'll try to spec out a better way to do this... 

This is related to https://github.com/ipython/ipython/pull/5896


Resolving patch:
diff --git a/IPython/html/widgets/widget_container.py b/IPython/html/widgets/widget_container.py
--- a/IPython/html/widgets/widget_container.py
+++ b/IPython/html/widgets/widget_container.py
@@ -2,58 +2,29 @@
 
 Represents a container that can be used to group other widgets.
 """
-#-----------------------------------------------------------------------------
-# Copyright (c) 2013, the IPython Development Team.
-#
+
+# Copyright (c) IPython Development Team.
 # Distributed under the terms of the Modified BSD License.
-#
-# The full license is in the file COPYING.txt, distributed with this software.
-#-----------------------------------------------------------------------------
 
-#-----------------------------------------------------------------------------
-# Imports
-#-----------------------------------------------------------------------------
 from .widget import DOMWidget
 from IPython.utils.traitlets import Unicode, Tuple, TraitError
 
-#-----------------------------------------------------------------------------
-# Classes
-#-----------------------------------------------------------------------------
-
 class ContainerWidget(DOMWidget):
     _view_name = Unicode('ContainerView', sync=True)
 
     # Child widgets in the container.
     # Using a tuple here to force reassignment to update the list.
     # When a proper notifying-list trait exists, that is what should be used here.
-    children = Tuple()
-    _children = Tuple(sync=True)
-
+    children = Tuple(sync=True)
 
     def __init__(self, **kwargs):
         super(ContainerWidget, self).__init__(**kwargs)
         self.on_displayed(ContainerWidget._fire_children_displayed)
 
     def _fire_children_displayed(self):
-        for child in self._children:
+        for child in self.children:
             child._handle_displayed()
 
-    def _children_changed(self, name, old, new):
-        """Validate children list.
-
-        Makes sure only one instance of any given model can exist in the 
-        children list.
-        An excellent post on uniqifiers is available at 
-            http://www.peterbe.com/plog/uniqifiers-benchmark
-        which provides the inspiration for using this implementation.  Below
-        I've implemented the `f5` algorithm using Python comprehensions."""
-        if new is not None:
-            seen = {}
-            def add_item(i):
-                seen[i.model_id] = True
-                return i
-            self._children = [add_item(i) for i in new if not i.model_id in seen]
-
 
 class PopupWidget(ContainerWidget):
     _view_name = Unicode('PopupView', sync=True)


Test patch: