Skip to content

Commit

Permalink
fix: avoid using anonymous functions with debounce, scheduleOnce, etc. (
Browse files Browse the repository at this point in the history
#150)

* fix(deps): update misc. deps

* ember-decorators
* plotly.js
* eslint-plugin-ember
* eslint-plugin-node
* testdouble

* fix: don't use anonymous functions with debounce or scheduleOnce

This not only appeases the new linter rule but might also
prevent some unexpected behavior / bugs.
  • Loading branch information
jacobq authored Oct 1, 2019
1 parent b1eee0a commit a98f84f
Show file tree
Hide file tree
Showing 3 changed files with 1,103 additions and 1,205 deletions.
22 changes: 14 additions & 8 deletions addon/components/plot-ly.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ export default class PlotlyComponent extends Component {
}

this.set('layout', layout);
this.set('_resizeEventHandler', () => {
log('_resizeEventHandler');
debounce(this, () => {
log('debounced _resizeEventHandler');
scheduleOnce('afterRender', this, '_onResize');
}, 200); // TODO: Make throttling/debouncing/whatever more flexible/configurable
});
this._logUnrecognizedPlotlyEvents();
}

Expand Down Expand Up @@ -168,11 +161,24 @@ export default class PlotlyComponent extends Component {
return parameters;
}

// TODO: Make throttling/debouncing/whatever more flexible/configurable
_resizeEventHandler() {
log('_resizeEventHandler');
debounce(this, this._debouncedResizeEventHandler, 200);
}

_debouncedResizeEventHandler() {
log('_debouncedResizeEventHandler firing (scheduling _onResize to run after next render)');
scheduleOnce('afterRender', this, this._onResize);
}

_onResize() {
log('_onResize');
log('_onResize firing');
this._plotly.then(Plotly => Plotly.Plots.resize(this.elementId));
}



_bindPlotlyEventListeners() {
if (this.get('_parameters.isResponsive')) {
window.addEventListener('resize', this._resizeEventHandler);
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"ember-auto-import": "1.3.0",
"ember-cli-babel": "7.8.0",
"ember-cli-htmlbars": "3.0.1",
"ember-decorators": "6.1.0",
"ember-decorators": "6.1.1",
"ember-lodash": "4.19.5",
"plotly.js": "1.49.4"
"plotly.js": "1.49.5"
},
"devDependencies": {
"@ember/optional-features": "0.7.0",
Expand Down Expand Up @@ -66,12 +66,12 @@
"ember-source-channel-url": "2.0.1",
"ember-truth-helpers": "2.1.0",
"ember-try": "1.2.1",
"eslint-plugin-ember": "6.7.0",
"eslint-plugin-node": "9.1.0",
"eslint-plugin-ember": "7.1.0",
"eslint-plugin-node": "10.0.0",
"loader.js": "4.7.0",
"qunit-dom": "0.9.0",
"safe-json-stringify": "1.2.0",
"testdouble": "3.12.0"
"testdouble": "3.12.4"
},
"engines": {
"node": "8.* || >= 10.*"
Expand Down
Loading

0 comments on commit a98f84f

Please sign in to comment.