Skip to content

Commit

Permalink
fix: clone data in fromData (#602)
Browse files Browse the repository at this point in the history
- in the clear case, `fromData` would set `this._data = pointGroups`,
  which made the pointer the same as the one for the parameter
  - as `this._data` is internally mutated, this would cause the input
    parameter to also be mutated as a side-effect

- this input mutation side-effect is likely unintended, so patched it so
  that the data is cloned in _all_ cases, not only in the append case
  - in the clear case, `this._data` is set to an empty array by
    `this.clear()`, so this is equivalent to `[].concat(pointGroups)`,
    which will result in them all being cloned
  • Loading branch information
agilgur5 authored Apr 3, 2022
1 parent 42bacae commit e5057c5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/signature_pad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export default class SignaturePad extends SignatureEventTarget {
this._drawDot.bind(this),
);

this._data = clear ? pointGroups : this._data.concat(pointGroups);
this._data = this._data.concat(pointGroups);
}

public toData(): PointGroup[] {
Expand Down

0 comments on commit e5057c5

Please sign in to comment.