Skip to content

Conversation

@dmsnell
Copy link
Owner

@dmsnell dmsnell commented May 2, 2024

Resolves google#39

It can be useful to extract Diff elements using destructuring
assignment. For example:

const a = dmp.diff_main('abc', 'ab123c', false);
const [eq, str] = a[0];

Because the Diff object is not an array, however, this is not
possible, even though it acts like an array.

In this patch a new Symbol.iterator method is added to the Diff
class so that this pattern can be used.

Props: @JackuB, @GrosSacASac, @TheSpyder

Resolves google#39

It can be useful to extract `Diff` elements using destructuring
assignment. For example:

```js
const a = dmp.diff_main('abc', 'ab123c', false);
const [eq, str] = a[0];
```

Because the `Diff` object is not an array, however, this is not
possible, even though it acts like an array.

In this patch a new `Symbol.iterator` method is added to the `Diff`
class so that this pattern can be used.

Props: @JackuB, @GrosSacASac, @TheSpyder
Co-authored-by: Cyril Walle <cyril.walle@protonmail.com>
@dmsnell dmsnell changed the base branch from master to main May 2, 2024 04:42
@dmsnell dmsnell merged commit 70f5f62 into main May 2, 2024
@dmsnell dmsnell deleted the javascript/make-diff-destructurable branch May 2, 2024 04:43
@dmsnell dmsnell mentioned this pull request May 2, 2024
@TheSpyder
Copy link

oh I was about to add this to my PR 😂 thank you 👍

@dmsnell
Copy link
Owner Author

dmsnell commented May 2, 2024

oh I was about to add this to my PR 😂 thank you 👍

we were talking back and forth and I figured that instead of asking you to do so I might as well just push it out. what's the point of having a fork if you don't push through your own work? 🙃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JavaScript: Diff is not iterable

3 participants