Skip to content

Commit db935c1

Browse files
Fix createOutputs, rename 'modeldb' origin to 'silent-change' (#254)
1 parent 5464226 commit db935c1

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

javascript/src/ycell.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
660660
events: Y.YEvent<any>[],
661661
transaction: Y.Transaction
662662
) => {
663-
if (transaction.origin !== 'modeldb') {
663+
if (transaction.origin !== 'silent-change') {
664664
this._changed.emit(this.getChanges(events));
665665
}
666666
};
@@ -771,27 +771,28 @@ export class YCodeCell
771771

772772
createOutputs(outputs: Array<nbformat.IOutput>): Array<Y.Map<any>> {
773773
const newOutputs: Array<Y.Map<any>> = [];
774-
for (const output of outputs) {
775-
let _newOutput: { [id: string]: any };
776-
const newOutput = new Y.Map();
774+
for (const output of JSONExt.deepCopy(outputs)) {
775+
let _newOutput1: { [id: string]: any };
777776
if (output.output_type === 'stream') {
778777
// Set the text field as a Y.Text
779778
const { text, ...outputWithoutText } = output;
780-
_newOutput = outputWithoutText;
779+
_newOutput1 = outputWithoutText;
781780
const newText = new Y.Text();
782781
let length = 0;
783782
// text is a list of strings
784783
for (const str of text as string[]) {
785784
newText.insert(length, str);
786785
length += str.length;
787786
}
788-
_newOutput['text'] = newText;
787+
_newOutput1['text'] = newText;
789788
} else {
790-
_newOutput = output;
789+
_newOutput1 = output;
791790
}
792-
for (const [key, value] of Object.entries(_newOutput)) {
793-
newOutput.set(key, value);
791+
const _newOutput2: [string, any][] = [];
792+
for (const [key, value] of Object.entries(_newOutput1)) {
793+
_newOutput2.push([key, value]);
794794
}
795+
const newOutput = new Y.Map(_newOutput2);
795796
newOutputs.push(newOutput);
796797
}
797798
return newOutputs;

0 commit comments

Comments
 (0)