@@ -112,47 +112,32 @@ def source(self, value):
112
112
}
113
113
]
114
114
# workaround until ypy is fixed: https://github.com/davidbrochart/ypy-websocket/pull/9
115
- ytexts_to_clear = []
116
115
with self ._ydoc .begin_transaction () as t :
117
116
# clear document
118
117
cells_len = len (self ._ycells )
119
118
if cells_len :
120
- self ._ycells .delete (t , 0 , cells_len )
119
+ self ._ycells .delete_range (t , 0 , cells_len )
121
120
for key in self ._ymeta :
122
- self ._ymeta .delete (t , key )
121
+ self ._ymeta .pop (t , key )
123
122
for key in [k for k in self ._ystate if k != "dirty" ]:
124
- self ._ystate .delete (t , key )
123
+ self ._ystate .pop (t , key )
125
124
126
125
# initialize document
127
126
ycells = []
128
127
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" ])
136
129
if "outputs" in cell :
137
130
cell ["outputs" ] = Y .YArray (cell ["outputs" ])
138
131
ycell = Y .YMap (cell )
139
132
ycells .append (ycell )
140
133
141
134
if ycells :
142
- self ._ycells .push (t , ycells )
135
+ self ._ycells .extend (t , ycells )
143
136
self ._ymeta .set (t , "metadata" , nb ["metadata" ])
144
137
self ._ystate .set (t , "nbformat" , nb ["nbformat" ])
145
138
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 )
149
139
150
140
def observe (self , callback ):
151
141
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 )
158
143
self ._subscriptions [self ._ymeta ] = self ._ymeta .observe (callback )
0 commit comments