dont mutate maps or mirror #28

Closed
BrianHung wants to merge 1 commit from mapping-immutable-maps-mirror-arrays into master
BrianHung commented 2024-10-25 09:04:41 +02:00 (Migrated from github.com)

Was reverting tracked changes and noticed that appendMap mutates the original array passed into new Mapping. Doesn't happen in the example code but happened in my codebase where I didn't defensively clone the maps array.

Was [reverting tracked changes](https://github.com/ProseMirror/website/blob/09f795d07f3717f2041a9936df4f052b381f90aa/example/track/index.js#L257) and noticed that `appendMap` mutates the original array passed into `new Mapping`. Doesn't happen in the example code but happened in my codebase where I didn't defensively clone the maps array.
marijnh commented 2024-10-25 18:16:14 +02:00 (Migrated from github.com)

I don't think this is a good idea. It will make building up bigger maps with appendMap take quadratic time, and generally introduce a lot of unnecessary copies. Does attached patch look like a reasonable solution?

I don't think this is a good idea. It will make building up bigger maps with `appendMap` take quadratic time, and generally introduce a lot of unnecessary copies. Does attached patch look like a reasonable solution?
BrianHung commented 2024-10-25 20:13:14 +02:00 (Migrated from github.com)

Yep, copying the original array once when appendMap is called for the first time works too.

Yep, copying the original array once when `appendMap` is called for the first time works too.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
prosemirror/prosemirror-transform!28
No description provided.