Skip to content

Tree: Add buildFieldAnchor, and fix Bug#12687

Merged
CraigMacomber merged 4 commits into
microsoft:mainfrom
CraigMacomber:cursor_work
Oct 26, 2022
Merged

Tree: Add buildFieldAnchor, and fix Bug#12687
CraigMacomber merged 4 commits into
microsoft:mainfrom
CraigMacomber:cursor_work

Conversation

@CraigMacomber
Copy link
Copy Markdown
Contributor

@CraigMacomber CraigMacomber commented Oct 26, 2022

Description

This adds ITreeSubscriptionCursor.buildFieldAnchor and ITreeCursor.getFieldPath to support it.

Additionally, this tweaks the Cursor tests cover a few more cases, and caught and fixes a bug in the handling of fields named proto: object.DefineProperty must be used to set such fields on objects!

This also changes a few uses of Object.getOwnPropertyNames() to Object.keys() where enumerating fields from map like objects. Both actually work (as long as there are no non enumerable properties like methods), but only including enumerable properties seems more semantically correct and would work in more cases (though we don't care about those cases, it seems more robust).

@CraigMacomber CraigMacomber requested a review from a team as a code owner October 26, 2022 21:07
@github-actions github-actions Bot added area: dds Issues related to distributed data structures public api change Changes to a public API base: main PRs targeted against main branch labels Oct 26, 2022
parent,
field: "key",
});
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency:

Suggested change
});
});

Comment thread packages/dds/tree/src/test/cursor.spec.ts
Comment thread packages/dds/tree/src/tree/cursor.ts Outdated
enterNode(childIndex: number): void;

/**
* @returns a path to the current node.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion: it could be useful to add an example of what the path should look like.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a link to FieldUpPath which defines this format. Putting example object literals inline here would be annoying to maintain if changing the FieldUpPath, so I think its better to just refer to it.

Comment thread packages/dds/tree/src/tree/treeTextFormat.ts
Craig Macomber and others added 3 commits October 26, 2022 15:16
@CraigMacomber CraigMacomber merged commit 24b2031 into microsoft:main Oct 26, 2022
@CraigMacomber CraigMacomber deleted the cursor_work branch October 26, 2022 22:51
CraigMacomber added a commit that referenced this pull request Oct 26, 2022
## Description

Fix same bug as in #12687 except in cursorToJsonObject and generic JS
object clone code for perf comparison.

The old code would change the prototype of the object (via the __proto__
field defined on the prototype), while the new code adds an enumerable
own property that shadows __proto__.

benchmarks show a slight slowdown with this change, around 2-3% for
cursorToJsonObject, and around 6% for the raw JS object clone reference.
sharptrip pushed a commit to sharptrip/FluidFramework that referenced this pull request Oct 28, 2022
## Description

This adds ITreeSubscriptionCursor.buildFieldAnchor and
ITreeCursor.getFieldPath to support it.

Additionally, this tweaks the Cursor tests cover a few more cases, and
caught and fixes a bug in the handling of fields named __proto__:
object.DefineProperty must be used to set such fields on objects!

This also changes a few uses of Object.getOwnPropertyNames() to
Object.keys() where enumerating fields from map like objects. Both
actually work (as long as there are no non enumerable properties like
methods), but only including enumerable properties seems more
semantically correct and would work in more cases (though we don't care
about those cases, it seems more robust).
sharptrip pushed a commit to sharptrip/FluidFramework that referenced this pull request Oct 28, 2022
## Description

Fix same bug as in microsoft#12687 except in cursorToJsonObject and generic JS
object clone code for perf comparison.

The old code would change the prototype of the object (via the __proto__
field defined on the prototype), while the new code adds an enumerable
own property that shadows __proto__.

benchmarks show a slight slowdown with this change, around 2-3% for
cursorToJsonObject, and around 6% for the raw JS object clone reference.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: dds Issues related to distributed data structures base: main PRs targeted against main branch public api change Changes to a public API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants