Skip to content

Commit

Permalink
Chore: Apply minor code corrections.
Browse files Browse the repository at this point in the history
  • Loading branch information
f1ames committed Sep 26, 2024
1 parent b08eccf commit f09915b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/useMultiRootEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ const useMultiRootEditor = ( props: MultiRootHookProps ): MultiRootHookReturns =
data || /* istanbul ignore next -- @preserve: It should never happen, data should be always filled. */ {}
);

const hasModifiedData = dataKeys.filter( rootName =>
const modifiedRoots = dataKeys.filter( rootName =>
editorData[ rootName ] !== undefined &&
JSON.stringify( editorData[ rootName ] ) !== JSON.stringify( data[ rootName ] )
);
Expand All @@ -531,7 +531,10 @@ const useMultiRootEditor = ( props: MultiRootHookProps ): MultiRootHookReturns =
};

const _updateEditorData = ( roots: Array<string> ) => {
const dataToUpdate = roots.reduce( ( result, rootName ) => ( { ...result, [ rootName ]: data[ rootName ] } ), {} );
const dataToUpdate = roots.reduce(
( result, rootName ) => ( { ...result, [ rootName ]: data[ rootName ] } ),
Object.create( null )
);
instance.data.set( dataToUpdate, { suppressErrorInCollaboration: true } as any );
};

Expand All @@ -552,8 +555,8 @@ const useMultiRootEditor = ( props: MultiRootHookProps ): MultiRootHookReturns =
_handleNewRoots( newRoots );
_handleRemovedRoots( removedRoots );

if ( hasModifiedData.length ) {
_updateEditorData( hasModifiedData );
if ( modifiedRoots.length ) {
_updateEditorData( modifiedRoots );
}

if ( rootsWithChangedAttributes.length ) {
Expand Down

0 comments on commit f09915b

Please sign in to comment.