U
    ÷Õ/e  ã                   @  sN   d dl mZ d dlZd dlmZ G dd„ dƒZdd„ Zedd	„ ƒZd
d„ ZdS )é    )ÚannotationsN)Úwithout_property_validationc                   @  s    e Zd ZdZdd„ Zdd„ ZdS )ÚDashboardComponentaT  Base class for Dask.distributed UI dashboard components.

    This class must have two attributes, ``root`` and ``source``, and one
    method ``update``:

    *  source: a Bokeh ColumnDataSource
    *  root: a Bokeh Model
    *  update: a method that consumes the messages dictionary found in
               distributed.bokeh.messages
    c                 C  s   d | _ d | _d S ©N)ÚsourceÚroot)Úself© r	   úM/tmp/pip-unpacked-wheel-g426oqom/distributed/dashboard/components/__init__.pyÚ__init__   s    zDashboardComponent.__init__c                 C  s   dS )z=Reads from bokeh.distributed.messages and updates self.sourceNr	   )r   Úmessagesr	   r	   r
   Úupdate   s    zDashboardComponent.updateN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r	   r	   r	   r
   r      s   r   c                   s,   t  |¡‰ |  ‡ fdd„|¡ t| |ƒ dS )a²  Add periodic callback to doc in a way that avoids reference cycles

    If we instead use ``doc.add_periodic_callback(component.update, 100)`` then
    the component stays in memory as a reference cycle because its method is
    still around.  This way we avoid that and let things clean up a bit more
    nicely.

    TODO: we still have reference cycles.  Docs seem to be referred to by their
    add_periodic_callback methods.
    c                     s   t ˆ ƒS r   ©r   r	   ©Úrefr	   r
   Ú<lambda>)   ó    z'add_periodic_callback.<locals>.<lambda>N)Úweakrefr   Úadd_periodic_callbackÚ_attach)ÚdocÚ	componentÚintervalr	   r   r
   r      s    
r   c                 C  s   | ƒ }|d k	r|  ¡  d S r   r   )r   Úcompr	   r	   r
   r   -   s    r   c                 C  s"   t | dƒstƒ | _| j |¡ d S )NÚ
components)ÚhasattrÚsetr   Úadd)r   r   r	   r	   r
   r   4   s    
r   )	Ú
__future__r   r   Zbokeh.core.propertiesr   r   r   r   r   r	   r	   r	   r
   Ú<module>   s   
