Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
shuntian committed Sep 27, 2023
1 parent 435d25c commit 97d2043
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 30 deletions.
32 changes: 3 additions & 29 deletions tests/core/stub-editor/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Editor } from 'slate';
import { createSdocEditor, formatChildren2 } from '../utils';

class StubEditor {
Expand All @@ -8,44 +7,19 @@ class StubEditor {
throw new Error('Param input is required');
}
this.editor = createSdocEditor(input, plugins);
this.pendingOperationList = [];
}

getEditor = () => {
return this.editor;
}
};

getContent = () => {
return formatChildren2(this.editor.children);
}
};

getStringContent = () => {
return JSON.stringify(this.getContent());
}

applyOperations = (operations) => {
const editor = this.editor;
Editor.withoutNormalizing(editor, () => {
operations.forEach(op => editor.apply(op));
});
const ops = editor.operations.slice();
this.pendingOperationList.push(ops);
editor.operations = [];
}

getPendingOperationList = () => {
return this.pendingOperationList;
}

resetPendingOperationList = () => {
const { operations } = this.editor;
this.pendingOperationList = [];
this.pendingOperationList.push(operations);
}

clearPendingOperationList = () => {
this.pendingOperationList = [];
}
};

}

Expand Down
2 changes: 1 addition & 1 deletion tests/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const createSdocEditor = (editor, plugins) => {
});

return editor;

};

export const formatChildren = (node) => {
Expand Down

0 comments on commit 97d2043

Please sign in to comment.