From a0669f874e591af013866f51492e128fe37fb563 Mon Sep 17 00:00:00 2001 From: idlewinn Date: Mon, 9 Mar 2020 23:37:42 -0700 Subject: [PATCH] add comments --- src/components/App.tsx | 6 ++++++ src/element/mutateElement.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/components/App.tsx b/src/components/App.tsx index ba4e29d8..2cf85774 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -263,9 +263,14 @@ export class App extends React.Component { sceneAppState || getDefaultAppState(), { scrollToContent: true }, ); + // Perform reconciliation - in collaboration, if we encounter + // elements with more staler versions than ours, ignore them + // and keep ours. if (elements == null || elements.length === 0) { elements = restoredState.elements; } else { + // create a map of ids so we don't have to iterate + // over the array more than once. const elementMap = elements.reduce( ( acc: { [key: string]: ExcalidrawElement }, @@ -276,6 +281,7 @@ export class App extends React.Component { }, {}, ); + // Reconcile elements = restoredState.elements.map(element => { if ( elementMap.hasOwnProperty(element.id) && diff --git a/src/element/mutateElement.ts b/src/element/mutateElement.ts index 72823322..21752534 100644 --- a/src/element/mutateElement.ts +++ b/src/element/mutateElement.ts @@ -3,6 +3,9 @@ import { MutableExcalidrawTextElement, } from "./types"; +// This function tracks updates of text elements for the purposes for collaboration. +// The version is used to compare updates when more than one user is working in +// the same drawing. export function mutateElement( element: MutableExcalidrawElement, callback: (mutatableElement: MutableExcalidrawElement) => void, @@ -11,6 +14,9 @@ export function mutateElement( callback(element); } +// This function tracks updates of text elements for the purposes for collaboration. +// The version is used to compare updates when more than one user is working in +// the same document. export function mutateTextElement( element: MutableExcalidrawTextElement, callback: (mutatableElement: MutableExcalidrawTextElement) => void,