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

remove ember-copy dependency #387

Merged
merged 1 commit into from
May 22, 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"ember-auto-import": "^2.7.2",
"ember-cli-babel": "^8.2.0",
"ember-cli-htmlbars": "^6.3.0",
"ember-copy": "^2.0.1",
"lodash-es": "^4.17.21",
"webpack": "^5.91.0"
},
"devDependencies": {
Expand Down
6 changes: 4 additions & 2 deletions tests/dummy/app/components/chart-highstock-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

import { copy } from 'ember-copy';
import stockData from '../data/stock';
import cloneDeep from 'lodash-es/cloneDeep';

const clone = window.structuredClone ?? cloneDeep;

export default class BarBasic extends Component {
@service('dynamic-chart')
Expand All @@ -18,7 +20,7 @@ export default class BarBasic extends Component {
},
};

chartData = copy(stockData, true);
chartData = clone(stockData);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Gaurav0 I know this is an old PR, but is there any chance there is anything structuredClone doesn't support in this chart data? I know it won't copy functions for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While many things don't work with structuredClone, it is faster and better than ember-copy in what it does support.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, but is there anything we will break by making the switch?

Copy link
Contributor Author

@Gaurav0 Gaurav0 May 16, 2024

Choose a reason for hiding this comment

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

Anything that uses copy or the Copyable mixin, without directly adding ember-copy as a dependency, maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Keep in mind that functions, DOM nodes, etc. cannot really be "cloned" in JavaScript. ember-copy creates a reference in the new object to the original, which "silently works" in some cases, but breaks when you actually switch JavaScript contexts. IMO, an error is better. And chart data shouldn't contain these anyway. However, it is up to you to decide whether this is a "bugfix" or a "breaking change". My 2 cents is document it and call it a bugfix.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm fine with that. Just wanted to double check. Thanks!


@action
updateSeriesData() {
Expand Down
6 changes: 4 additions & 2 deletions tests/dummy/app/components/chart-line-interactive.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { copy } from 'ember-copy';
import { inject as service } from '@ember/service';
import Component from '@glimmer/component';
import commitStats from '../data/commit-stats';
import { action } from '@ember/object';
import cloneDeep from 'lodash-es/cloneDeep';

const clone = window.structuredClone ?? cloneDeep;

export default class BarBasic extends Component {
@service('dynamic-chart')
Expand All @@ -28,7 +30,7 @@ export default class BarBasic extends Component {
},
};

chartData = copy(commitStats, true);
chartData = clone(commitStats);

@action
updateSeriesData() {
Expand Down
6 changes: 4 additions & 2 deletions tests/dummy/app/services/dynamic-chart.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { copy } from 'ember-copy';
import Service from '@ember/service';
import cloneDeep from 'lodash-es/cloneDeep';

const clone = window.structuredClone ?? cloneDeep;

export default class DynamicChart extends Service {
getRandomInt(min, max) {
Expand All @@ -17,7 +19,7 @@ export default class DynamicChart extends Service {
}

updateSeriesCount(chartData, numSeries) {
let chartDataCopy = copy(chartData, true);
let chartDataCopy = clone(chartData);
return chartDataCopy.slice(0, numSeries);
}
}
8 changes: 5 additions & 3 deletions tests/integration/components/high-charts-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { copy } from 'ember-copy';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, settled } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import cloneDeep from 'lodash-es/cloneDeep';

const clone = window.structuredClone ?? cloneDeep;

import {
lineChartOptions,
Expand Down Expand Up @@ -65,7 +67,7 @@ module('Integration | Component | High Charts', function (hooks) {
.exists({ count: 3 }, 'base series count');

// add a series to chart content
let cityDataCopy = copy(cityData, true);
let cityDataCopy = clone(cityData);
cityDataCopy.push({
name: 'San Francisco',
data: [
Expand Down Expand Up @@ -96,7 +98,7 @@ module('Integration | Component | High Charts', function (hooks) {
.exists({ count: 3 }, 'base series count');

// remove a series from chart content
let cityDataCopy = copy(cityData, true);
let cityDataCopy = clone(cityData);
cityDataCopy = cityDataCopy.slice(0, 2);

this.set('cityData', cityDataCopy);
Expand Down
14 changes: 6 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4588,7 +4588,7 @@ ember-cli-babel-plugin-helpers@^1.0.0, ember-cli-babel-plugin-helpers@^1.1.1:
resolved "https://registry.yarnpkg.com/ember-cli-babel-plugin-helpers/-/ember-cli-babel-plugin-helpers-1.1.1.tgz#5016b80cdef37036c4282eef2d863e1d73576879"
integrity sha512-sKvOiPNHr5F/60NLd7SFzMpYPte/nnGkq/tMIfXejfKHIhaiIkYFqX8Z9UFTKWLLn+V7NOaby6niNPZUdvKCRw==

ember-cli-babel@^7.10.0, ember-cli-babel@^7.13.0, ember-cli-babel@^7.22.1, ember-cli-babel@^7.23.0, ember-cli-babel@^7.23.1, ember-cli-babel@^7.26.11, ember-cli-babel@^7.26.6, ember-cli-babel@^7.7.3:
ember-cli-babel@^7.10.0, ember-cli-babel@^7.13.0, ember-cli-babel@^7.23.0, ember-cli-babel@^7.23.1, ember-cli-babel@^7.26.11, ember-cli-babel@^7.26.6, ember-cli-babel@^7.7.3:
version "7.26.11"
resolved "https://registry.yarnpkg.com/ember-cli-babel/-/ember-cli-babel-7.26.11.tgz#50da0fe4dcd99aada499843940fec75076249a9f"
integrity sha512-JJYeYjiz/JTn34q7F5DSOjkkZqy8qwFOOxXfE6pe9yEJqWGu4qErKxlz8I22JoVEQ/aBUO+OcKTpmctvykM9YA==
Expand Down Expand Up @@ -4944,13 +4944,6 @@ ember-compatibility-helpers@^1.1.2, ember-compatibility-helpers@^1.2.0:
fs-extra "^9.1.0"
semver "^5.4.1"

ember-copy@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/ember-copy/-/ember-copy-2.0.1.tgz#13192b12a250324bb4a8b4547a680b113f4e3041"
integrity sha512-N/XFvZszrzyyX4IcNoeK4mJvIItNuONumhPLqi64T8NDjJkxBj4Pq61rvMkJx/9eZ8alzE4I8vYKOLxT0FvRuQ==
dependencies:
ember-cli-babel "^7.22.1"

ember-load-initializers@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ember-load-initializers/-/ember-load-initializers-2.1.2.tgz#8a47a656c1f64f9b10cecdb4e22a9d52ad9c7efa"
Expand Down Expand Up @@ -7978,6 +7971,11 @@ locate-path@^7.1.0:
dependencies:
p-locate "^6.0.0"

lodash-es@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==

lodash._baseflatten@^3.0.0:
version "3.1.4"
resolved "https://registry.yarnpkg.com/lodash._baseflatten/-/lodash._baseflatten-3.1.4.tgz#0770ff80131af6e34f3b511796a7ba5214e65ff7"
Expand Down
Loading