Skip to content

Commit

Permalink
Restructure for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
flekschas committed Nov 18, 2017
1 parent 68164a4 commit 520c232
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/components/HiGlassLauncher.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import PropTypes from 'prop-types';
import React from 'react';

// Utils
import { deepClone, Logger, removeHiGlassEventListeners } from '../utils';
import {
debounce,
deepClone,
Logger,
removeHiGlassEventListeners
} from '../utils';

// Configs
import { SELECT } from '../configs/mouse-tools';
Expand All @@ -21,6 +26,8 @@ class HiGlassLauncher extends React.Component {
super(props);

this.hiGlassEventListeners = [];

this.updateViewConfigDb = debounce(this.updateViewConfig.bind(this), 1000);
}

componentWillUnmount() {
Expand Down Expand Up @@ -79,13 +86,7 @@ class HiGlassLauncher extends React.Component {

this.hiGlassEventListeners.push({
event: 'viewConfig',
id: this.api.on('viewConfig', (newViewConfig) => {
this.newViewConfig = JSON.parse(newViewConfig);

if (!deepEqual(this.newViewConfig, this.props.viewConfig)) {
this.props.setViewConfig(this.newViewConfig);
}
}),
id: this.api.on('viewConfig', this.updateViewConfigDb),
});
}

Expand Down Expand Up @@ -130,6 +131,14 @@ class HiGlassLauncher extends React.Component {
this.api.activateTool('move');
}
}

updateViewConfig(newViewConfig) {
this.newViewConfig = JSON.parse(newViewConfig);

if (!deepEqual(this.newViewConfig, this.props.viewConfig)) {
this.props.setViewConfig(this.newViewConfig);
}
}
}

HiGlassLauncher.defaultProps = {
Expand Down

0 comments on commit 520c232

Please sign in to comment.