diff --git a/experimental/dds/tree2/src/feature-libraries/editable-tree-2/lazyField.ts b/experimental/dds/tree2/src/feature-libraries/editable-tree-2/lazyField.ts index 2dedf2970da1..f68e1c0dbf65 100644 --- a/experimental/dds/tree2/src/feature-libraries/editable-tree-2/lazyField.ts +++ b/experimental/dds/tree2/src/feature-libraries/editable-tree-2/lazyField.ts @@ -346,14 +346,14 @@ export class LazySequence } } } - const count = sourceEnd - sourceStart; + const movedCount = sourceEnd - sourceStart; let destinationIndex = index; if (sourceField === this) { if (destinationIndex > sourceStart) { destinationIndex = destinationIndex < sourceEnd - ? sourceStart // distination overlaps with source range -> slide to left - : (destinationIndex -= count); // destination after source range -> subtract count + ? sourceStart // destination overlaps with source range -> slide to left + : (destinationIndex -= movedCount); // destination after source range -> subtract moved count } } assertValidIndex(destinationIndex, this, true); @@ -362,7 +362,7 @@ export class LazySequence this.context.editor.move( sourceFieldPath, sourceStart, - count, + movedCount, destinationFieldPath, destinationIndex, ); diff --git a/experimental/dds/tree2/src/feature-libraries/editable-tree-2/proxies/proxies.ts b/experimental/dds/tree2/src/feature-libraries/editable-tree-2/proxies/proxies.ts index 284add0de45c..765812f3dec8 100644 --- a/experimental/dds/tree2/src/feature-libraries/editable-tree-2/proxies/proxies.ts +++ b/experimental/dds/tree2/src/feature-libraries/editable-tree-2/proxies/proxies.ts @@ -130,9 +130,11 @@ export function createObjectProxy { // To satisfy 'deepEquals' level scrutiny, the target of the proxy must be an object with the same - // 'null prototype' you would get from on object literal '{}' or 'Object.create(null)'. This is - // because 'deepEquals' uses 'Object.getPrototypeOf' as a way to quickly reject objects with different - // prototype chains. + // prototype as an object literal '{}'. This is because 'deepEquals' uses 'Object.getPrototypeOf' + // as a way to quickly reject objects with different prototype chains. + // + // (Note that the prototype of an object literal appears as '[Object: null prototype] {}', not because + // the prototype is null, but because the prototype object itself has a null prototype.) // TODO: Although the target is an object literal, it's still worthwhile to try experimenting with // a dispatch object to see if it improves performance. @@ -205,7 +207,7 @@ export function createObjectProxy( list: SharedTreeList, @@ -227,15 +229,17 @@ function itemsAsContextuallyTyped( iterable: Iterable>, ): Iterable { // If the iterable is not already an array, copy it into an array to use '.map()' below. - const asArray = Array.isArray(iterable) ? iterable : Array.from(iterable); - - return asArray.map(asContextuallyTypedData); + return Array.isArray(iterable) + ? iterable.map(asContextuallyTypedData) + : Array.from(iterable, asContextuallyTypedData); } // TODO: Experiment with alternative dispatch methods to see if we can improve performance. -/** PropertyDescriptorMap used to build the prototype for our dispatch object. */ -const prototypeProperties: PropertyDescriptorMap = { +/** + * PropertyDescriptorMap used to build the prototype for our SharedListNode dispatch object. + */ +const listPrototypeProperties: PropertyDescriptorMap = { // We manually add [Symbol.iterator] to the dispatch map rather than use '[fn.name] = fn' as // above because 'Array.prototype[Symbol.iterator].name' returns "values" (i.e., Symbol.iterator // is an alias for the '.values()' function.) @@ -383,12 +387,12 @@ const prototypeProperties: PropertyDescriptorMap = { // Array.prototype.unshift, Array.prototype.values, ].forEach((fn) => { - prototypeProperties[fn.name] = { value: fn }; + listPrototypeProperties[fn.name] = { value: fn }; }); /* eslint-enable @typescript-eslint/unbound-method */ -const prototype = Object.create(Object.prototype, prototypeProperties); +const prototype = Object.create(Object.prototype, listPrototypeProperties); /** * Helper to coerce property keys to integer indexes (or undefined if not an in-range integer).