Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: simplify viewbox cloning #935

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/core/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ Canvas.prototype._viewboxChanged = function() {
Canvas.prototype.viewbox = function(box) {

if (box === undefined && this._cachedViewbox) {
return JSON.parse(JSON.stringify(this._cachedViewbox));
return structuredClone(this._cachedViewbox);
}

const viewport = this._viewport,
Expand Down
13 changes: 2 additions & 11 deletions test/spec/core/CanvasSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,20 +869,11 @@ describe('Canvas', function() {

it('should return copy of viewbox', inject(function(canvas) {

// given
canvas.addShape({ id: 's0', x: 0, y: 0, width: 300, height: 300 });

var shape = canvas.addShape({ id: 's1', x: 10000, y: 0, width: 300, height: 300 });

var viewbox = canvas.viewbox(),
viewboxStringified = JSON.stringify(viewbox);

// when
canvas.scrollToElement(shape);
var viewbox = canvas.viewbox();

// then
expect(JSON.stringify(viewbox)).to.eql(viewboxStringified);
expect(JSON.stringify(canvas.viewbox())).not.to.eql(viewboxStringified);
expect(viewbox).to.not.equal(canvas.viewbox());
}));


Expand Down
Loading