@@ -112,47 +112,32 @@ def source(self, value):
112112 }
113113 ]
114114 # workaround until ypy is fixed: https://github.com/davidbrochart/ypy-websocket/pull/9
115- ytexts_to_clear = []
116115 with self ._ydoc .begin_transaction () as t :
117116 # clear document
118117 cells_len = len (self ._ycells )
119118 if cells_len :
120- self ._ycells .delete (t , 0 , cells_len )
119+ self ._ycells .delete_range (t , 0 , cells_len )
121120 for key in self ._ymeta :
122- self ._ymeta .delete (t , key )
121+ self ._ymeta .pop (t , key )
123122 for key in [k for k in self ._ystate if k != "dirty" ]:
124- self ._ystate .delete (t , key )
123+ self ._ystate .pop (t , key )
125124
126125 # initialize document
127126 ycells = []
128127 for cell in nb ["cells" ]:
129- cell_source = cell ["source" ]
130- if cell_source :
131- ytext = Y .YText (cell_source )
132- else :
133- ytext = Y .YText (" " )
134- ytexts_to_clear .append (ytext )
135- cell ["source" ] = ytext
128+ cell ["source" ] = Y .YText (cell ["source" ])
136129 if "outputs" in cell :
137130 cell ["outputs" ] = Y .YArray (cell ["outputs" ])
138131 ycell = Y .YMap (cell )
139132 ycells .append (ycell )
140133
141134 if ycells :
142- self ._ycells .push (t , ycells )
135+ self ._ycells .extend (t , ycells )
143136 self ._ymeta .set (t , "metadata" , nb ["metadata" ])
144137 self ._ystate .set (t , "nbformat" , nb ["nbformat" ])
145138 self ._ystate .set (t , "nbformatMinor" , nb ["nbformat_minor" ])
146- with self ._ydoc .begin_transaction () as t :
147- for ytext in ytexts_to_clear :
148- ytext .delete (t , 0 , 1 )
149139
150140 def observe (self , callback ):
151141 self .unobserve ()
152- for cell in self ._ycells :
153- self ._subscriptions [cell ["source" ]] = cell ["source" ].observe (callback )
154- if "outputs" in cell :
155- self ._subscriptions [cell ["outputs" ]] = cell ["outputs" ].observe (callback )
156- self ._subscriptions [cell ] = cell .observe (callback )
157- self ._subscriptions [self ._ycells ] = self ._ycells .observe (callback )
142+ self ._subscriptions [self ._ycells ] = self ._ycells .observe_deep (callback )
158143 self ._subscriptions [self ._ymeta ] = self ._ymeta .observe (callback )
0 commit comments