Skip to content

Commit

Permalink
refactor: refine method naming
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed Jul 28, 2024
1 parent c634077 commit 4421987
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export {
export type { LoroDocType } from "./lib";
export {
createNodeFromLoroObj,
updateLoroOnPmChange,
updateLoroToPmState,
ROOT_DOC_KEY,
NODE_NAME_KEY,
CHILDREN_KEY,
Expand Down
7 changes: 3 additions & 4 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ export const NODE_NAME_KEY = "nodeName";
*/
export const WEAK_NODE_TO_LORO_CONTAINER_MAPPING = new WeakMap<Node, ContainerID>();

export function updateLoroOnPmChange(
export function updateLoroToPmState(
doc: LoroDocType,
mapping: LoroNodeMapping,
oldEditorState: EditorState,
newEditorState: EditorState,
editorState: EditorState,
) {
const node = newEditorState.doc;
const node = editorState.doc;
const map = doc.getMap(ROOT_DOC_KEY);

let isInit = false;
Expand Down
4 changes: 2 additions & 2 deletions src/sync-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
LoroNodeMapping,
clearChangedNodes,
createNodeFromLoroObj,
updateLoroOnPmChange,
updateLoroToPmState,
} from "./lib";

export const loroSyncPluginKey = new PluginKey<LoroSyncPluginState>("loro-sync");
Expand Down Expand Up @@ -68,7 +68,7 @@ export const LoroSyncPlugin = (props: LoroSyncPluginProps): Plugin => {
}
switch (meta?.type) {
case "doc-changed":
updateLoroOnPmChange(state.doc as LoroDocType, state.mapping, oldEditorState, newEditorState);
updateLoroToPmState(state.doc as LoroDocType, state.mapping, oldEditorState, newEditorState);
break;
case "update-state":
state = { ...state, ...meta.state };
Expand Down
16 changes: 8 additions & 8 deletions tests/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
createNodeFromLoroObj,
getLoroMapAttributes,
getLoroMapChildren,
updateLoroOnPmChange,
updateLoroToPmState,
} from "../src/lib";

import { schema } from "./schema";
Expand Down Expand Up @@ -198,7 +198,7 @@ describe("updateDoc", () => {
const editorState = createEditorState(schema, examplePmContent.doc);
const loroDoc: LoroDocType = new Loro();
const mapping: LoroNodeMapping = new Map();
updateLoroOnPmChange(loroDoc, mapping, editorState, editorState);
updateLoroToPmState(loroDoc, mapping, editorState, editorState);
expect(loroDoc.toJSON()).toEqual(exampleLoroContent);
});

Expand All @@ -212,7 +212,7 @@ describe("updateDoc", () => {
pmContent["content"] = [];
let editorState = createEditorState(schema, pmContent);

updateLoroOnPmChange(loroDoc, mapping, editorState, editorState);
updateLoroToPmState(loroDoc, mapping, editorState, editorState);
expect(loroDoc.toJSON()).toEqual({
[ROOT_DOC_KEY]: {
nodeName: ROOT_DOC_KEY,
Expand All @@ -228,7 +228,7 @@ describe("updateDoc", () => {
});
editorState = createEditorState(schema, pmContent);

updateLoroOnPmChange(loroDoc, mapping, editorState, editorState);
updateLoroToPmState(loroDoc, mapping, editorState, editorState);
expect(loroDoc.toJSON()).toEqual({
[ROOT_DOC_KEY]: {
nodeName: ROOT_DOC_KEY,
Expand All @@ -250,7 +250,7 @@ describe("updateDoc", () => {
});
editorState = createEditorState(schema, pmContent);

updateLoroOnPmChange(loroDoc, mapping, editorState, editorState);
updateLoroToPmState(loroDoc, mapping, editorState, editorState);
expect(loroDoc.toJSON()).toEqual({
[ROOT_DOC_KEY]: {
nodeName: ROOT_DOC_KEY,
Expand Down Expand Up @@ -287,7 +287,7 @@ describe("updateDoc", () => {
});
editorState = createEditorState(schema, pmContent);

updateLoroOnPmChange(loroDoc, mapping, editorState, editorState);
updateLoroToPmState(loroDoc, mapping, editorState, editorState);
expect(loroDoc.toJSON()).toEqual({
[ROOT_DOC_KEY]: {
nodeName: ROOT_DOC_KEY,
Expand Down Expand Up @@ -343,7 +343,7 @@ describe("updateDoc", () => {
});
editorState = createEditorState(schema, pmContent);

updateLoroOnPmChange(loroDoc, mapping, editorState, editorState);
updateLoroToPmState(loroDoc, mapping, editorState, editorState);
expect(loroDoc.toJSON()).toEqual({
[ROOT_DOC_KEY]: {
nodeName: ROOT_DOC_KEY,
Expand Down Expand Up @@ -395,7 +395,7 @@ describe("createNodeFromLoroObj", () => {
const _editorState = createEditorState(schema, examplePmContent.doc);
const loroDoc: LoroDocType = new Loro();
const mapping: LoroNodeMapping = new Map();
updateLoroOnPmChange(loroDoc, mapping, _editorState, _editorState);
updateLoroToPmState(loroDoc, mapping, _editorState, _editorState);

const node = createNodeFromLoroObj(
schema,
Expand Down

0 comments on commit 4421987

Please sign in to comment.